【问题标题】:How use UITabBar without UITabBarController如何在没有 UITabBarController 的情况下使用 UITabBar
【发布时间】:2015-04-19 08:35:06
【问题描述】:

我需要将 UITabBar 与 UITabBarItem 一起使用,但我需要在情节提要中不使用 UITabBarController 的情况下执行此操作。

我在firstViewController 中添加了TabBarTabBarItem,但我无法在我的类中触发或添加事件方法。

这样做的正确方法是什么?有人可以概述下一步要采取的步骤吗?

谢谢。

【问题讨论】:

  • 你能添加一些代码 sn -p 吗?
  • 现在我只创建故事板......我有一个 MFSideMenu(右),我也需要一个 TabBar.......我在网上阅读了这个方法: - (void)tabBar:( UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { if ([item.title isEqualToString:@"Messaggi"]) { // 或者你的标题是什么 [self performSegueWithIdentifier:@"segueMessaggi" sender:self]; } } 但我无法触发它...
  • 这段代码似乎是对的,将 'UITabBarDelegate' 协议添加到类文件中,然后在类 'viewDidLoad()' 中制作 'self.delegate = self'
  • 对不起,但对我来说这是第一次添加协议....我在我的 .h @interface myViewController 中读到: UIViewController 对吗?现在??在我的.m?你能回答我的问题吗??谢谢
  • 是的,现在只需调用 - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item in your .m file

标签: objective-c events segue uitabbar uitabbaritem


【解决方案1】:

要在 UI 元素上实现特定行为,您需要实现相应的协议


在 IOS 中实现协议的语法

@interface myViewController : UIViewController<UITabBarDelegate>

这样你就可以实现使用UITabBar的方法


更多细节我希望你通过官方文档https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaEncyclopedia/DelegatesandDataSources/DelegatesandDataSources.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-17
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 2021-10-30
    • 1970-01-01
    相关资源
    最近更新 更多