现在的位置: 首页 > 综合 > 正文

ios 4.3 中 viewDidAppear没有被调用的解决办法

2013年06月14日 ⁄ 综合 ⁄ 共 824字 ⁄ 字号 评论关闭

在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.

如果是直接把View Controller的view addSubview到另一个View,则不会调用viewDidAppear,你需要手动发送viewDidAppear给这个View Controll

解决办法,就是手工触发一下:

  1. [self.contentView addSubview:[s6View view]];  
  2. [s6View viewDidAppear:YES];  

有网友做过测试后,得出以下结论

补充说明,viewWillAppear和viewDidAppear的情况是一样的,在iPhone上,除了第1次加载xib文件时肯定会调用外,其他任何情况都不会自动调用:无论popViewControllerAnimate、presentModalViewController还是addSubviews。但iPad上则相反,除了addSubviews方法外,都一定会调用。此外,测试是在ios4.3设备上进行的。


抱歉!评论已关闭.