Programmatically pressing a UITabBar button in Xcode

前端 未结 6 1261
无人及你
无人及你 2020-12-17 17:34

Sorry for the newbie question. I have a UITabBar in my main window view as well as an array of UINavigationControllers for each Tab. The structure is similar to the iPod a

6条回答
  •  执念已碎
    2020-12-17 18:16

    [self.parentViewController.tabBarController setSelectedIndex:3];
    

    Selected the index for me but it just highlighted the navbarcontroller's index as the active index, but while it highlighted that index it was actually on a different viewcontroller than was suggested by the tabbarmenu item.

    Just wanted to add that I used this from my view controller, and it performed like someone actually pressed the menuitem; from code:

    UITabBarController *MyTabController = (UITabBarController *)((AppDelegate*) [[UIApplication sharedApplication] delegate]).window.rootViewController;
    [MyTabController setSelectedIndex:1];
    

    Thank you for this post/answers it helped out a lot in my project.

提交回复
热议问题