我在加载所选选项卡项目的 View 时遇到问题。
我在 UIViewController
的 viewDidLoad
中使用以下代码,位于 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 。
最佳答案
在 viewDidAppear: 方法中编写代码,而不是在 view did load 中编写代码。 它会起作用的..
关于iphone - 以编程方式从 UITabBarController 选择选项卡并加载 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15781777/