缘由: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];
}