5
votes

I'm creating a tab bar application using the built-in tab bar app template in Xcode. I have 4 tabs, one of which is a mapView. For a few of the view controllers my code programmatically sets the selected index of the tab bar depending on the user actions. For the mapView view controller I have a method that presents a modal view when the user taps on a selected annotation. The modal view has some information about that selected annotation. I can dismiss the modal view controller and return to the mapView correctly.

My problem is that I would like to put a 'home' button on the modal view controller that should dismiss the modal view and take the user to 0 index on the tab bar (AKA home). The mapView is index 3.

I cannot do a [self.tab setSelectedIndex:0] from the modal view attached to the home button - it doesn't work. Perhaps I'm overthinking this. Can anyone offer a solution / hint? I greatly appreciate it! Thanks.

1

1 Answers

5
votes

When you present a modal view controller from one of the tabs, the tab bar controller instance becomes the parentViewController of the modal view controller. You can use this property to call the tab bar controller methods.

[(UITabBarController *)self.parentViewController setSelectedIndex:0];