Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
431 views
in Technique[技术] by (71.8m points)

ios - How can I programmatically set selected tab of UITabBarController while also triggering shouldSelectViewController in UITabBarControllerDelegate

I'm trying to animate the transitions between tabs in my UITabBarController, which is working fine when I push on the tab buttons. However, when I switch tabs programmatically by calling

[self.tabBarController setSelectedIndex:2];

in a swipe gesture recognizer, the shouldSelectViewController function is NOT being called in my UITabBarControllerDelegate delegate, and therefore my animation isn't being triggered.

Is there a way to accomplish what I want? Can I programmatically trigger the tab switch differently perhaps so that the shouldSelectViewController function gets called?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you have implemented - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController in your tabBarController's delegate than you can call it manually.

[self.tabBarController.delegate tabBarController:self.tabBarController shouldSelectViewController:[[tabBar viewControllers] objectAtIndex:2]];
[self.tabBarController setSelectedIndex:2];

Hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...