1

I have following storyboard. There is an OrderViewController and when I open the app first time, it calls -(void) viewWillAppear: (BOOL) animated method, but when I open another app (putting this app in the background), and then coming back to this app again, viewWillAppear method is not getting called again?

enter image description here

jscs
  • 63,694
  • 13
  • 151
  • 195
casillas
  • 16,351
  • 19
  • 115
  • 215

1 Answers1

7

You sent the viewWillAppear message when your view is added to the window's view hierarchy.

The window's view hierarchy doesn't change when the app moves from the background to foreground, so the message isn't sent for that event.

If you want to know (in your view controller) when your app is coming to the foreground, you should listen for either the UIApplicationWillEnterForeground notification or the UIApplicationWillBecomeActive notification (or both), depending on your precise needs.

Read “Strategies for Handling App State Transitions” in the App Programming Guide for iOS for more information about when these notifications are sent.

Forge
  • 6,538
  • 6
  • 44
  • 64
rob mayoff
  • 375,296
  • 67
  • 796
  • 848