为什么viewDidAppear不调用?什么时候调用
来源:互联网 发布:手机支架 知乎 编辑:程序博客网 时间:2024/05/04 14:26
苹果的文档是这样描述的:
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 Controller。
那么我们是不是可以这样认为:
pushViewController,或presentModelViewController这个View Controller时,会调用它的viewDidAppear方法呢?苹果文档中未说明。
事实上即使是用presentModelviewController,viewDidAppear也不一定能被调用。测试的结果表明:如果nib第1次加载的时候,viewDidAppear一定会调用的。但如果第2次加载这个nib则不一定会调用。viewDidLoad则无论何种情况总是调用的,所以要保险得多。另外,在iPad中没有这样的问题,viewDidAppear总是会调用的。
补充说明,viewWillAppear和viewDidAppear的情况是一样的,在iPhone上,除了第1次加载xib文件时肯定会调用外,其他任何情况都不会自动调用:无论popViewControllerAnimate、presentModalViewController还是addSubviews。但iPad上则相反,除了addSubviews方法外,都一定会调用。此外,测试是在ios4.3设备上进行的。
btw:viewDidLoad方法只有在initWithNibName时会调用。
如果ViewController是在TabViewController中加载的,则等同于addSubView。当TabViewController第一次显示时,这个ViewController的viewDidLoad方法会调用,而viewDidAppear方法不会调用。但是当点击TabBarItem时则恰巧相反,只会调用ViewController的viewDidAppear而不会调用viewDidLoad。
- 为什么viewDidAppear不调用?什么时候调用
- iOS -- 为什么viewDidAppear不调用?什么时候调用
- viewDidAppear什么时候调用?
- iOS: viewWillAppear和viewDidAppear什么时候被调用
- viewWillAppear和viewDidAppear什么时候被调用
- ios 自定义tabbar时 viewDidAppear不调用
- viewDidAppear中一定要调用[super viewDidAppear]
- Android之什么时候调用onSaveInstance方法的时候(为什么按Home键盘会调用,按Back不调用)
- ios的视图控制器的viewWillAppear和viewDidAppear什么时候被调用
- ios的视图控制器的viewWillAppear和viewDidAppear什么时候被调用
- 为什么cellForRowAtIndexPath方法不调用?
- recorderChild()函数在什么时候调用,为什么不用SetZorder()
- onNewIntent 什么时候调用
- onNewIntent 什么时候调用
- surfaceDestroyed什么时候被调用
- onNewIntent 什么时候调用
- probe在什么时候调用
- layoutSubviews什么时候触发调用
- 黑客之google入侵网站常用方式
- 十进制数字转Unicode字符—十六进制数字转Unicode字符
- 最近的一次系统“维护”和更新
- HTML5之拖动图片
- 运算符重载实例
- 为什么viewDidAppear不调用?什么时候调用
- C/C++ 代码分析警告
- 让emacs完美显示中文
- 查找数组中不存在的两个数字
- 请记得,我不是个好人
- Setup failed to configure the server. Refer to the server error logs and setup error logs for more i
- c#读取XML内容实现动态加载菜单
- hdu 1879 继续畅通工程
- js文字编码函数escape,encodeURI,encodeURIComponent 的使用