viewWillAppear中,viewDidAppear不會被調用,不費一槍
症狀(這是兩個問題的答案,因爲它花了相當多的挖掘,找到真正的答案。):viewWillAppear
,viewDidAppear
沒有被稱爲在我的UIViewController 。
原因:嵌入UINavigationController
或UITabBarController
(我的情況)在UIViewController
以某種方式中斷與調用這些方法。
解決方法:在包含上述UINavigationController
/UITabBarController
的UIViewController
中手動調用它們。
例如(假設projectNavigationController
是你UINavigationController
):
-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [projectNavigationController viewWillAppear:animated]; } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [projectNavigationController viewWillDisappear:animated]; } -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [projectNavigationController viewDidAppear:animated]; } -(void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; [projectNavigationController viewDidDisappear:animated]; }
在我來說,我有一個內部UITabBarController
和我相應地調用方法,一切都解決了。
(上解決署名:http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/)
只是因爲我很好奇...:爲什麼你會將標籤欄控制器包裝到另一個viewcontroller? :)在大多數情況下,它們是視圖(控制器)層次結構的根... – Toastor 2010-08-24 20:23:20
+1 ..真的解決了我的問題..乾杯 – 2011-05-09 17:14:27