解決:IOS viewDidAppear/viewWillAppear無法被調用


本文轉載至 http://my.oschina.net/lvlove/blog/82264

 

 

原因:

蘋果的文檔是這樣描述的:

If the view belonging to a view controlleris added to a view hierarchy directly, the view controller will not receivethis message. If you insert or add a view to the view hierarchy, and it has aview controller, you should send the associated view controller this messagedirectly. Failing to send the view controller this message will prevent anyassociated animation from being displayed.

    實際情況中,在addSubview, presentModelviewController或者TabViewController中加載viewController時,viewDidAppear/viewWillAppear都是無法被調用的。(iphone)

解決:

     如果是pushViewController的情況,可以直接利用UINavigationControllerDelegate,這樣:

.h文件中:

<UINavigationControllerDelegate>

.m文件中:

   self.navigationController.delegate =self

-(void)navigationController:(UINavigationControlle*)

    navigationController willShowViewController:

    (UIViewController *)viewController animated:(BOOL)animated  

{    

    [viewController viewWillAppear:animated];

}

-(void)navigationController:(UINavigationControlle*) 

    navigationController didShowViewController:

    (UIViewController *)viewController animated:(BOOL)animated

{

    [viewController viewDidAppear:animated];

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM