(这既是问题又是答案,因为需要大量挖掘才能找到真正的答案。)
症状:viewWillAppear
,viewDidAppear
在我的 UIViewController 中没有被调用。
原因:在调用这些方法时嵌入一个UINavigationController
或UITabBarController
(我的情况)以某种方式中断。UIViewController
UIViewController
解决方案:在包含上述UINavigationController
/的文件中手动调用它们UITabBarController
。
例如(假设projectNavigationController
是你的UINavigationController
):
-(void)viewWillAppear:(BOOL)动画{ [超级viewWillAppear:动画]; [projectNavigationController viewWillAppear:animated]; } -(void)viewWillDisappear:(BOOL)动画{ [超级viewWillDisappear:动画]; [projectNavigationController viewWillDisappear:animated]; } -(void)viewDidAppear:(BOOL)动画{ [超级 viewDidAppear:动画]; [projectNavigationController viewDidAppear:animated]; } -(无效)viewDidDisappear:(BOOL)动画{ [超级 viewDidDisappear:动画]; [projectNavigationController viewDidDisappear:animated]; }
就我而言,我有一个内在的UITabBarController
,我相应地调用了方法,一切都解决了。
(解决方案的归属:http: //davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/)