iOS Push to TabBarController

2019-09-02 13:43发布

问题:

i have several viewcontrollers, and at the last viewcontroller, i want when the users click on a button present in this view, he goes on a other view controller which contains tabbarcontroller.

For example, i've something like this :

How can i go from the first view, to the tab bar controller ?

EDIT : i tried to just set a push from the button to the tab bar controller, but it's not runnin g correctly.

回答1:

Create a segue in the Interface Builder, give it a unique identifier, then call that segue in your code using

[self performSegue:@"segueIdentifier" sender:self];


回答2:

You have to embed the button's view controller in a UINavigationController, otherwise you will get an error like this:

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.'

Once I put it in a UINavigationController, it transitioned just fine in my tests.

If you do not want a UINavigationController, you can set the segue to Modal, and it should also transition to the Tab Bar, but modally.