简体   繁体   中英

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

why? and what can i do if i want to do something when the view of an controller will appear in 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.

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.

As a result, when you add the navigation controller to your view it doesn't get 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; and (ii) if so, posting artificial viewWillAppear/viewDidAppear/viewWillDisappear/viewDidDisappear to your contained controllers.

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

[*] and you should also call addChildViewController: to make sure all messages move correctly in all directions

I think it may be related to the "View Controller Abusing". Check if your container view controller is used correctly. You can refer to this post for detail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM