在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设备上进行的。
本文详细解释了在使用Xcode4.2.1和iOS5 SDK发布应用时,若直接将ViewController的view添加到另一个View层次中,会导致viewDidAppear方法无法自动调用。通过手动触发添加子视图和调用viewDidAppear方法,可以解决这一问题。测试表明,此方法仅适用于iOS4.3设备,并且在不同设备和情境下有不同的行为表现。
383

被折叠的 条评论
为什么被折叠?



