简体   繁体   中英

Having trouble calling a ViewController with .xib file from storyboard in iOS

I have an application where I have a ViewController in my storyboard file. I have added a button to this viewController that should call another ViewController that is outside of the storyboard and has with it, it's own .xib file. However, when I press this button, the method is being called, but the new screen is not being loaded, and I don't know why.

Here is the relevant code that I have below:

- (IBAction)showTireCount:(id)sender {

    NSLog(@"do i get called?");
    SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    [self.navigationController pushViewController:secondView animated:YES];

}

I am able to see the text "do i get called" appear in the system output, but unfortunately nothing else occurs. Can anyone see what it is I am doing wrong?

self.navigationController is nil. Did you embed your view controller (the one with the button) in a UINavigationController?

确保您在SecondViewController的初始化方法中包含以下语句

[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

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