Eric Smith
Eric Smith

Reputation: 1376

How do you change views from a Tab Bar Controller

I am developing an app that consists of a Tab Bar Controller that points to 3 view controllers (all with tabs). In one of these tab views I've made a button and I want it to open a new view (without a tab at the bottom). This new view would need a navigation bar with a back button to return to the previous view, so I was thinking I need to create a navigation controller?

Essentially this is what I'm trying to do (I apologize for the poorly drawn diagram). enter image description here

How can I get this new view (entirely independent of the tab bar controller) to display programatically? Would this require a navigation controller?

Upvotes: 0

Views: 99

Answers (2)

matt
matt

Reputation: 535925

You are describing a presented view controller. Call presentViewController:animated:completion:.

I very frequently do this with a navigation bar and a Back or Done button, just as you describe. But it's not a navigation controller or navigation interface; it's just a convenient way of showing the user how to get back.

For example, this is a presented view in one of my apps. The top is a navigation bar, and the cancel button gets us back (call dismissViewController...). The rest is a scrolling view (a UICollectionView) of buttons.

enter image description here

Upvotes: 3

William Falcon
William Falcon

Reputation: 9823

[myTabBar setSelectedIndex:1]

You may have to access the tabBar like self.tabBarController so… [self.tabBarController setSelectedIndex:1];

1 is index 1 in the tabbar's stack (this is like tapping a tabBar button manually)

Upvotes: 0

Related Questions