緣由:iphone
蘋果的文檔是這樣描述的:this
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.spa
實際狀況中,在addSubview, presentModelviewController或者TabViewController中加載viewController時,viewDidAppear/viewWillAppear都是沒法被調用的。(iphone)orm
解決:ip
若是是pushViewController的狀況,能夠直接利用UINavigationControllerDelegate,這樣:ci
.h文件中:文檔
<UINavigationControllerDelegate>animation
.m文件中:it
self.navigationController.delegate =selfio
-(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];
}