I'm experiencing some difficulties doing a rather simple thing, I'm missing something but don't see...
I reproduced the issue with a very simple App (using IB) :
- App's main ViewController is a UINavigationController.
- NavigationController's root is "FirstViewController".
- FirstViewController and SecondViewController are empty UIViewController subclasses.
- Their XIB files where generated by XCode when creating the classes, AutoLayout is enabled.
- I placed Labels on top and bottom of SecondViewController (Vertical space constraints = 0).
Using ChildViewControllers
Problem is if I display SecondViewController via "ChildViewControllers" method, it goes wrong on my iPhone4: I don't see bottom label.
// In FirstViewController.m
- (IBAction)child:(id)sender {
[self addChildViewController:self.secondVC];
[self.view addSubview:self.secondVC.view];
[self.secondVC didMoveToParentViewController:self];
}
Using NavigationController
If I display "SecondViewController" through the NavigationController, everything is fine, SecondViewController is displayed properly.
// In FirstViewController.m
- (IBAction)push:(id)sender {
[self.navigationController pushViewController:self.secondVC animated:YES];
}
Also, as soon as SecondViewController has been displayed once through NavigationController, it'll be always well displayed.
I'm surely missing something, but what? :p Do you have any ideas?
I Uploaded the simple project on dropbox: https://dl.dropbox.com/u/36803737/sharebox/AutoLayoutTest.zip
Thanks!
julien
self.secondVC.view.frame = self.view.frame;
in child method. What do you think about that? – Prakrit