在xcode4.2.1中使用ios 5的sdk。发布的时候选择target是4.3。出现viewDidAppear方法没有被调用。
苹果的官方解释
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.
解决办法,就是手工触发一下:
- [self.contentView addSubview:[s6View view]];
- [s6View viewDidAppear:YES];
有网友做过测试后,得出以下结论
补充说明,viewWillAppear和viewDidAppear的情况是一样的,在iPhone上,除了第1次加载xib文件时肯定会调用外,其他任何情况都不会自动调用:无论popViewControllerAnimate、presentModalViewController还是addSubviews。但iPad上则相反,除了addSubviews方法外,都一定会调用。此外,测试是在ios4.3设备上进行的。