我有一个基于导航的应用,其中一个视图显示工具栏。如果我按Home键并重新输入应用程序,工具栏会隐藏自己。我试图在viewDidAppear / viewWillAppear中取消隐藏,但它们从不开火。
取消隐藏工具栏的适当位置在哪里?
答案 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
}