How to show a UINavigationController with an UIBut

2019-07-22 13:38发布

问题:

in my application the first view is an UIView with a couple of uilabel and an uibutton to do the login. I would to show an uinavigationcontroller with a table after the login, so with the action of the button. I know how to set up a working Navigation Controller starting with the Xcode Template but i dont know how to load this as a "Second View"

Any help?

回答1:

You can add the view of the UINavigationController to the UIWindow and either let it obscure the first view or remove that view from the UIWindow. The navigationController won't have a back button to take you back to the first view (since it's stack doesn't include the first controller), so you'll need a custom button if you want to provide a way back.

- (IBAction) buttonPressed {
    myNavigationController = [[UINavigationController alloc] initWithRootViewController:mySecondViewController];
    [self.view.window addSubview:myNavigationController.view];
    [self.view removeFromSuperview];
}

That's the direct answer to your question, however, if you simply want UINavigationController functionality but don't want to see the UINavigationBar on the first screen - check out:

Hiding the UINavigationBar only for the root UIViewController