iPhone视图WillAppear不触发 [英] iPhone viewWillAppear not firing

查看:79
本文介绍了iPhone视图WillAppear不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您不是刚才创建视图层次结构,我已阅读了许多有关 viewWillAppear 有问题的人的帖子。我的问题是我不知道这是什么意思。



如果我创建一个 RootViewController c $ c> addSubView ,我希望添加的视图连接到 viewWillAppear 事件。



任何人都有一个复杂的程序化视图层次结构的示例,它成功地在每个级别接收 viewWillAppear p>

苹果的文档状态:


警告:如果视图属于视图控制器直接添加到视图层次结构,视图控制器将不会收到此消息。如果向视图层次结构插入或添加视图,并且它具有视图控制器,则应直接向相关联的视图控制器发送此消息。未能发送视图控制器此消息将阻止显示任何关联的动画。


问题是,他们没有描述去做这个。什么是直接的意思。你如何间接添加一个视图。



我对Cocoa和iPhone相当新,所以如果有一些有用的例子,除了基本的Hello World



非常感谢任何帮助...

解决方案

如果您使用导航控制器并设置其委托,则不会调用视图{Will,Did} {Appear,Disappear}。



您需要使用导航控制器委托方法:

  navigationController:willShowViewController:animated:
navigationController:didShowViewController:animated:


I've read numerous posts about people having problems with viewWillAppear when you do not create your view hierarchy just right. My problem is I can't figure out what that means.

If I create a RootViewController and call addSubView on that controller, I would expect the added view(s) to be wired up for viewWillAppear events.

Does anyone have an example of a complex programmatic view hierarchy that successfully receives viewWillAppear events at every level?

Apple's Docs state:

Warning: If the view belonging to a view controller is added to a view hierarchy directly, the view controller will not receive this message. If you insert or add a view to the view hierarchy, and it has a view controller, you should send the associated view controller this message directly. Failing to send the view controller this message will prevent any associated animation from being displayed.

The problem is that they don't describe how to do this. What the hell does "directly" mean. How do you "indirectly" add a view.

I am fairly new to Cocoa and iPhone so it would be nice if there were useful examples from Apple besides the basic Hello World crap.

Any help is greatly appreciated...

解决方案

If you use a navigation controller and set its delegate, then the view{Will,Did}{Appear,Disappear} methods are not invoked.

You need to use the navigation controller delegate methods instead:

navigationController:willShowViewController:animated:
navigationController:didShowViewController:animated:

这篇关于iPhone视图WillAppear不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆