0

I have a UIlabel that shows a countdown and an observer:

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("willEnterForeground:"), name:UIApplicationWillEnterForegroundNotification, object: nil)

The problem is willEnterForeground() fires only after the view has become visible. If in that function I put a new value for the label like timerLabel.text = "blah", the user (on returning the app to foreground) will first see the value the label had on entering background, and only after like half a second the label text will be updated.

Is there a way to update views before they become visible?

TimSim
  • 3,936
  • 7
  • 46
  • 83
  • Because `viewWillAppear` does not fire on entering foreground. – TimSim Mar 26 '16 at 16:08
  • Ok, for anyone else in future have a look at this post - http://stackoverflow.com/questions/5277940/why-does-viewwillappear-not-get-called-when-an-app-comes-back-from-the-backgroun – Sam B Mar 26 '16 at 16:17

1 Answers1

2

Actually, your code is working. The problem is that the user first sees the snapshot that was taken when the app went into the background. Then your code runs, and then your real app appears — with the updated label text value.

So you are complaining that you don't like the way this whole snapshot thing works. There is not much you can do about it, though, as the snapshot has already been made. The only way to set that snapshot is to set the value of the label as the app goes into the background (and I presume that's impossible here, as you don't know the future).

What I recommend is that you blank the label as the app goes into the background. That way, at least, the user won't initially see the wrong value.

matt
  • 515,959
  • 87
  • 875
  • 1,141