重新启动应用程序时隐藏导航工具栏

时间:2012-06-12 20:21:24

标签: ios ios5

我有一个基于导航的应用,其中一个视图显示工具栏。如果我按Home键并重新输入应用程序,工具栏会隐藏自己。我试图在viewDidAppear / viewWillAppear中取消隐藏,但它们从不开火。

取消隐藏工具栏的适当位置在哪里?

1 个答案:

答案 0 :(得分: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
}
相关问题