0

I have a navigation based app where one of the views shows a toolbar. If I press the Home key and reenter the application the toolbar hides itself. I tried to unhide in viewDidAppear/viewWillAppear, but they never fire.

Where is the proper place to unhide the toolbar?

4

1 回答 1

2

当应用程序进入前台时,不会调用 ViewDidAppear/ViewWillAppear。要处理进入前台的应用程序,您需要创建一个通知。

在 Appdelegate 中将以下代码添加到 applicationWillEnterForeground:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[NSNotificationCenter defaultCenter] postNotificationName:       @"UIApplicationWillEnterForegroundNotification" object: nil];
}

然后在您各自的视图控制器中进行以下更改

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    [[NSNotificationCenter defaultCenter] addObserver: self
                                         selector: @selector(handleEnterForeground:)
                                             name:  @"UIApplicationWillEnterForegroundNotification"
                                           object: nil];
}

- (void) handleEnterForeground: (NSNotification*) sender
{
    //Do whatever you need to do to handle the enter foreground notification
}
于 2012-06-13T01:28:28.350 回答