我在创建 View Controller 后立即将其分配给选项卡。是否可以选择单击选项卡后显示的 View ?
例如 //用户点击标签1 如果(有消息) //显示 View A 别的 //显示 View B
最佳答案
是的,这是可能的。您需要为选项卡 Controller 设置委托(delegate):
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
tabBarController.delegate = self; // or whatever suitable class you have
此委托(delegate)需要符合 UITabBarControllerDelegate
协议(protocol)。
在您的委托(delegate)中,实现 tabBarController:didSelectViewController:
并在其中找出您要呈现的 View 。假设您的选项卡的 Root View Controller 是一个导航 Controller ,那么委托(delegate)方法实现将是这样的:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
/* logic goes here */
[viewController pushViewController:someNewVC animated:YES];
}
关于iphone - iOS - 是否可以在运行时为 uitabbar 选择 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12846403/