0
votes

1 tabbarcontroller connected to 3 navigation controllers. each navigation controller is connected to a view controller. in #3 a button segues modally to a view controller. i dont want the segue to be "push". is there anyway i can create a button in that view controller that segues back to #3?

I want a button in "randomviewcontroller" to perform a segue to "viewcontroller3" that is within a navigation controller and tabbarcontroller. "viewcontroller3" is the third tabbarbutton view.

so:

randomviewcontroller to perform segue to

TabBarController -(relationshipsegue)-> NavigationController -(rootview controllersegue)-> viewcontroller3

Example: a login view controller. you press login button, and it segues to the third tabbar button view (view that you see if you tap third icon on tabbar). third tabbar button is connected to a navigation controller that is rootview of a view controller.

2

2 Answers

3
votes

If the view controllers in the tabbarviewcontrollers.viewcontrollers array are all navigation controllers and you just want to programmatically switch tabs and show the root view controller of that navigation controller, then all you should need is to switch to the index of the tab you want to select:

tabBarController?.selectedIndex = 2 //or whatever index you want
1
votes

I'm not sure I quite understand your question (and I don't see why you would have a login view controller in one of your tabs, most likely it would be in a view controller of its own).

Try connecting the button to the following code (assuming that the button is in the login tab)

-(IBAction) login:(id)sender {
     [self.tabBar setSelectedItem:[self.tabBar.items objectAtIndex:2]];
}

Let me know if this works.