[英]“viewWillAppear” not call in xcode 4.5 with iPhone 4.3 simulator
"viewWillAppear" not call in xcode 4.5 with iphone 4.3 simulator, but if it runs in iPhone 5.0 or iPhone 6.0 simulator, this method will be called. “ viewWillAppear”不会在使用iPhone 4.3模拟器的xcode 4.5中调用,但是如果它在iPhone 5.0或iPhone 6.0模拟器中运行,则将调用此方法。
why? 为什么? and what can i do if i want to do something when the view of an controller will appear in ios 4.3?
当控制器的视图将出现在ios 4.3中时,如果我想做些什么怎么办?
Based on your comments, the problem appears to be the lack of container view controllers in iOS 4. As of 5+ you're explicitly meant to be able to add the view
of any controller into the view of any other* and that will generate the appropriate view[Will/Did]Appear
, along with all the other newer messages — viewDidLayoutSubviews
, etc. 根据您的意见,这个问题似乎是在IOS 4.由于5+缺乏容器视图控制器的你明确地意味着能够将添加
view
任何控制器到任何其他*的观点,这将产生适当的view[Will/Did]Appear
以及所有其他较新的消息viewDidLayoutSubviews
等。
In 4 you weren't explicitly allowed to build container view controllers and there's no deliberate, specific backwards link that connects a view back to its controller. 在4中,没有明确允许您构建容器视图控制器,也没有故意的,特定的向后链接将视图连接回其控制器。
As a result, when you add the navigation controller to your view it doesn't get viewDidAppear
. 结果,当您将导航控制器添加到视图时,它不会获得
viewDidAppear
。 Because it doesn't know that its view has appeared, it doesn't tell any of the controllers it contains that their views have appeared. 因为它不知道其视图已经出现,所以它不会告诉它包含的任何控制器其视图已经出现。
Probably the best you're going to be able to do is to hack around that by (i) checking if you're operating under iOS 4; 您可能要做的最好的办法就是(i)检查您是否在iOS 4下运行; and (ii) if so, posting artificial
viewWillAppear/viewDidAppear/viewWillDisappear/viewDidDisappear
to your contained controllers. (ii)如果是,则将人工
viewWillAppear/viewDidAppear/viewWillDisappear/viewDidDisappear
到您所包含的控制器中。
Based on personal experience, iOS 4 (at least in 4.3) does actually implement addChildViewController:
but not to do what the later, documented version does. 根据个人经验,iOS 4(至少在4.3中)确实实现了
addChildViewController:
但是不执行更高版本的文档。 So despite it not being an entirely accurate functionality check I tend to use if([self respondsToSelector:@selector(presentingViewController)])
to determine whether I need to propagate these messages manually. 因此,尽管它并不是完全准确的功能检查,但我还是倾向于使用
if([self respondsToSelector:@selector(presentingViewController)])
来确定是否需要手动传播这些消息。
[*] and you should also call addChildViewController:
to make sure all messages move correctly in all directions [*],并且您还应该调用
addChildViewController:
以确保所有消息在各个方向上都能正确移动
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.