A white screen is seen when attempting to switch between views!
I wanted to create a very simple method that switches between views in a view based application. For some reason, when the views are switched, the first view is removed and instead of viewing the second view, I see a white screen.
This is my method:
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstV开发者_Python百科iewController" bundle:nil];
self.view = firstViewController.view;
[firstViewController.view removeFromSuperview];
[firstViewController release];
secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
self.view = secondViewController.view;
I don't know why it is happening because I know that the second view's ViewDidLoad method is called (I put a NSLog there) - but the second view is not seen!
Any suggestions?
Thanks in advance,
Sagiftw
viewDidLoad's executing because initWithNibName:bundle: calls it. That doesn't mean that the view's actually being displayed.
I usually use this (removing initialisation/release logic):
[self.view addSubview: firstViewController.view];
[firstViewController.view removeFromSuperview];
[self.view addSubview: secondViewController.view];
精彩评论