iphone - iOS - 是否可以在运行时为 uitabbar 选择 View ?

标签 iphone ios uitabbarcontroller

我在创建 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/

相关文章:

iphone - 从 iPhone 上的音频流中获取 Hz 频率

ios - 从 UITableView 中删除行时以 NSException 类型的未捕获异常终止

swift - 从 UITabBar 按钮按下显示模态视图

iphone - 阻止用户以横向方式查看某些 View

ios - 将 iOS 键盘布局更改为表情符号?

ios - 在 UINavigationController 中推送 View Controller

iphone - 使用2G,3G,4G网络的iPhone应用程序

iphone - iOS 大学计划在 iPhone 上测试应用程序

iphone - 表头和表格单元格之间的空间

iphone - PushViewController 不适用于 Reveal Controller