我想在您单击某个选项卡(比如选项卡 [index] 3
)时触发一个操作,而不是显示一个新的 viewController
。
我找不到这样做的方法,有没有我可以实现的方法?
最佳答案
尝试以这种方式实现 – tabBarController:shouldSelectViewController:
UITabBarControllerDelegate
方法:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
BOOL shouldSelect = YES;
NSInteger tabToIgnore = 3;
if ([tabBarController.viewControllers indexOfObject:viewController] == tabToIgnore) {
shouldSelect = NO;
[self performSpecificAction];
}
return shouldSelect;
}
当您使用 View Controller 列表初始化 UITabBarController
对象时,您可以简单地使用 [[UIViewController alloc] init]
索引 3。
关于ios - 在执行方法而不是新 View Controller 的 UITabBar 上添加选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23640914/