Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

iphone - viewDidLoad gets called, viewWillAppear does not get called, view does not appear on screen

Update

It has been mentioned that viewWillAppear and viewDidAppear do not get called per the docs. However, I perform no initialization within these methods and no adding UI elements to the view.

I was just using them to place break points to try to debug this.

Any other ideas?


Original Question

I'm stumped. I'm refactoring some code and have come across some strange behavior....

I initialize viewController A without a nib and set the view programmatically.

viewDidLoad in controller A gets called.

Inside viewDidLoad of viewController A, I initialize viewController B from a nib.

I add viewControllerB.view as a subview of viewControllerA.view

viewDidload of controller B gets called.


Then it gets weird:

  1. viewWillAppear and viewDidAppear of viewController B never get called.

  2. viewControllerB.view never makes it on screen.

  3. No errors.


Things I checked:

The name of the viewControllerBs Nib is correct.

The view outlet of viewControllerB is connected to a view.

viewControllerB and its view both are non-nil.

And to top it off, everything works great in SDK [redacted] beta 5!

Any ideas? It's got to be something silly..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If the view controller is added to a view hierarchy through code, the view controller will not get viewWillAppear (or viewDidAppear) messages. If you add it yourself you have to send the view controller the message yourself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...