简体   繁体   中英

pushViewController leads to a black screen

I have an iOS project (not using Storyboards) that has 2 UITextField and 1 button (a login screen). When the user clicks the button, it launches a POST to the server that returns "1" if the user is in the database. And, then, goes to another screen.

The problem is, that screen show black. This is my code:

In requestFinished method:

if([responseString2 isEqualToString:(@"1")]){
termsViewController *termscreen=[[termsViewController alloc]init];
    [[self navigationController] pushViewController:termscreen animated:YES];
}

In the delegate class, in the method initDiddidFinishLaunchingWithOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[firstViewController alloc] initWithNibName:@"firstViewController" bundle:nil];
self.window.rootViewController = self.viewController;
//
UINavigationController *navcontroller= [[UINavigationController alloc]initWithRootViewController:self.viewController];
[[self window]setRootViewController:navcontroller];
[self.window makeKeyAndVisible];    
return YES;

}

It goes to another screen, shows the navigation bar...but the screen is black. I am new to iphone developing, so probably will be missing something.

Can anyone help me?

Thanks in advance.

I guess you are not assigning the nib file with it. Try this:

termsViewController *termscreen=[[termsViewController alloc] initWithNibName:@"termsViewController" bundle:nil];

I assume your view controller variable's name to be termsViewController , which you may change to fit your needs. I hope this helps. Happy coding :-)

I think this happened because your second view controller is not inside the navigation controller. When you create a nav controller you have to add an array of objects to it, so it knows what to push.

Code snippet:

UINavigationController *navContr = [[UINavigationController alloc]init];
FirstViewController *firstViewContr = [[FirstViewController alloc] init];
MapViewController *mapContr = [[MapViewController alloc] init];
NSArray *vcArray = [NSArray arrayWithObjects: mapContr, firstViewContr, nil];
[navContr setViewControllers:vcArray];
[self.window setRootViewController:navContr];
[self.window makeKeyAndVisible];
return YES;

Could be that you didn't implement (or deleted) the

- (void)loadView
{
    // If you create your views manually, you MUST override this method and use it to create your views.
    // If you use Interface Builder to create your views, then you must NOT override this method.
}

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