iphone - 以编程方式从 UITabBarController 选择选项卡并加载 View

标签 iphone uitabbarcontroller

我在加载所选选项卡项目的 View 时遇到问题。

我在 UIViewControllerviewDidLoad 中使用以下代码,位于 UITabBar 的第 1 项。

UITabBarController *tab = self.tabBarController;

if (tab){
   NSLog(@"I have a tab bar");
   [self.tabBarController setSelectedIndex:1];
   [self.tabBarController.view setNeedsDisplay];
   self.tabBarController.selectedIndex=1;
} else {
    NSLog(@"I don't have");
}

当我按返回选项卡 Controller 按钮时,它会选择选项卡,但不会打开所需的 View 。它显示索引 0 处的选项卡 View 。

enter image description here

最佳答案

在 viewDidAppear: 方法中编写代码,而不是在 view did load 中编写代码。 它会起作用的..

关于iphone - 以编程方式从 UITabBarController 选择选项卡并加载 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15781777/

相关文章:

iphone - 在 iPhone 应用程序中存储密码

iphone - 在 iPhone 和 iPad 上显示网站的整个宽度

ios - 尽管在 Controller 中设置 tabbar.hidden = NO,TabBar 仍然隐藏

ios - 如何在 swift ios 中刷新标签栏项目

objective-c - pushViewController 不适用于标签栏 Controller

ios - 如何自定义 UITableViewCell 的背景颜色?

iphone - iOS - NSNotificationCenter 内存泄漏

iPhone 。按钮图像不切换

ios - 在模态视图中使用导航 Controller 将 managedobjectContext 传递给 tabbarcontroller

ios - 如何在单击按钮时在 uitabbaritem 上打开新的 View Controller