开发者

Change Selected Index of Tab Bar Application from Modal View Controller

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.


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜