ios - 在 iOS6 中使用 Storyboard 子类化 UITabBarController

标签 ios uitabbarcontroller uistoryboard

我使用 iOS 6 ARC 和 Storyboards 开始了一个新项目

我制作了一个非常简单的应用程序,有一个选项卡栏和 2 个 View

enter image description here

现在我创建了一个 TestViewController 文件,它扩展了 UITabBarController 并将自定义类放入 Storyboard中。

现在的问题是我正在尝试实现一些委托(delegate)方法,例如

- (BOOL) tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;

但它从不调用它。谁能帮忙?

我还注意到,如果我将该代码放入第一个 View Controller 中,它就可以正常工作。看起来第一个 View Controller 之前覆盖了 TabBarController 。我很困惑。

为了进行更多测试,我在 TestViewController.m 中添加了一些日志记录:

- (void)viewDidLoad { 
   [super viewDidLoad];
   // Do any additional setup after loading the view.
   NSLog(@"%@",self.tabBarController.viewControllers);
}

并且 View Controller 为空。

我什至尝试这样做 self.tabBarController.delegate = self;

但还是没有解决。

最佳答案

TestViewController 是你的标签栏 Controller ,所以你的日志应该只是 self.viewControllers,而不是 self.tabBarController.viewControllers。您也不需要添加属性 viewControllers,因为您的子类从 UITabBarController 继承了该属性。您的委托(delegate)消息未被调用的原因是由于同样的问题。您应该使用(在 TestViewController 中)设置委托(delegate):

self.delegate = self;

这是假设您希望 TestViewController 成为委托(delegate),我不清楚这是否是您想要的。

关于ios - 在 iOS6 中使用 Storyboard 子类化 UITabBarController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17884957/

相关文章:

ios - 打开特定 View 的通知

ios - 我可以在同一 View Controller 中添加两个选项卡栏,一个选项卡栏在底部,一个选项卡栏在顶部

objective-c - Segue 未出现在图像选择器之后

ios - Storyboard instantiateViewControllerWithIdentifier 不设置 IBOutlets

ios - 由于 libWeANDSFLibrary.a(ASIReachability.o) 而导致的重复符号链接(symbolic link)器错误

ios - popViewControllerAnimated 后 UITextField 内容为空

ios - 如何通过有条件地加载 UIViewController 的 Storyboard添加 UITabBarItem

ios - "Slide"UITabBar View 之间的 segue

ios - CKQuery,如何从记录中获取所有字段?

ios - 我无法访问 tabbarcontroller 下的 View Controller