2012-06-12 53 views
0

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

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

回答

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 
}