简体   繁体   中英

Strange UINavigationController issue

I'm currently trying to use push segue to navigate between two views. This works fine elsewhere in my app, no problems. However, in this particular location, I'm presented with the following error:

 Terminating app due to uncaught exception 'NSGenericException',
 reason: 'Push segues can only be used when the source controller is
 managed by an instance of UINavigationController.

Now here's the thing, i know exactly what this error means, and exactly how to fix it.

Editor -> Embed in -> Navigation Controller on the view controller i'm trying to push from.

The thing is, I've done that already and the error persists. Any ideas?

For what it's worth, the navigation bar doesn't even appear in the view that was embedded inside the nav controller.

Here is the current setup

I have a ViewController on the storyboard that is setup to inherit from UIViewController. That controller is embedded inside a UINavigation controller via the above method.

On this view controller view, there are two buttons. Inside IB I have dragged a push segue from each of those buttons to the respective view controllers I would like to present.

I've also tried doing the segue in code via the following:

- (IBAction)btnTerms:(id)sender {
    UIViewController *termsVC = [STORYBOARD instantiateViewControllerWithIdentifier:@"TermsOfServicesViewController"];
    [self.navigationController pushViewController:termsVC animated:YES];
}

In the above case, nothing happens at all. No crashes or anything. Debugger breakpoints confirm that the method is being hit, though.

Update as per Phillip's question

UINavigationController *nav = self.navigationController;
[self.navigationController pushViewController:termsVC animated:YES];

在此处输入图片说明

在此处输入图片说明

- (IBAction) btnSignUpCLicked:(UIButton *)sender {

    [self presentViewController:[STORYBOARD instantiateViewControllerWithIdentifier:@"SignUpViewController"] animated:YES completion:nil];

}

From the comments:

Embedding a view controller inside a navigation controller will cause the embedded controller to load when its navigation controller does. The reverse is not implied (, which is reasonable because there might be a case where the embedded controller would be also useful standalone).

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