user1832333
user1832333

Reputation:

viewDidAppear isn't getting called after running from the background

Method viewDidAppear is not getting called after going from the background back into my iPhone Application.

Does anyone have a solution for this?

I need to call a method every time my MainViewController is shown (even after returning from the background) that will change a label to the new date.

viewDidAppear doesn't seem to be working properly.

Upvotes: 2

Views: 567

Answers (3)

prince
prince

Reputation: 924

Try using viewWillAppear if you dont mind doing this process before the is actually shown. Else you can use the method. - (void)applicationWillEnterForeground:(UIApplication *)application{}

Upvotes: 0

Purva
Purva

Reputation: 1291

You will have the UIApplicationWillEnterForegroundNotification method in App delegate.Now you need to create the object of the class you want and call the viewwillAppear

this method will be called when the app is in background.

- (void)applicationDidEnterBackground:(UIApplication *)application
{
}

now for the view will appear code like this

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    ViewController *vc = [ViewController alloc]init];//you can use your viewcontroller here

    [vc viewDidAppear:YES];// this will call the method.
}

Upvotes: 0

hsoi
hsoi

Reputation: 2764

Actually it is working properly.

Instead, consider installing a notification handler for UIApplicationDidBecomeActiveNotification or UIApplicationWillEnterForegroundNotification, whichever may be more appropriate for your situation. From there you could do an update of your GUI.

Upvotes: 1

Related Questions