【问题标题】:iOS: Implementing UITabBar from User Interface without a UITabBarControlleriOS:在没有 UITabBarController 的情况下从用户界面实现 UITabBar
【发布时间】:2011-07-23 14:49:25
【问题描述】:

在我的应用程序中,我有一个 UIViewController,我希望在其中添加一个 UITabBar。所以我通过用户界面添加了它(到 UIViewController.xib 文件中),并在 UIViewController.h+m 文件中创建了 IUTabBar 和 UITabBarItems 的实例。在 xib 文件中,我能够将代码项连接到 xib 上的代码项(通过从文件所有者拖动到相关项并选择相关的 IBOutlet),但我似乎无法将按钮连接回写在上的 IBActions h+m 个文件。

在添加 UITabBar 之前,我使用 UIToolBar 并且在进行这些连接时没有问题。

谁能解释我做错了什么?

【问题讨论】:

    标签: ios uitabbar uitoolbar ibaction iboutlet


    【解决方案1】:

    您应该实现UITabBarDelegate 协议(documentation here)。

    一旦你实现了这个协议,只需使用- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item 方法就可以知道用户何时更改了选项卡栏的选定项。在此方法的实现中,您必须检查选择了哪个项目,并基于此手动更改视图的内容。

    【讨论】:

    • 谢谢亚历克斯,我有一些澄清:
    • 1.当您说“您应该实现 UITabBarDelegate 协议”时,您的意思是将 UITabBarDelegate 继承添加到我的 UIViewController.h 文件中?像这样:@interface HowDoButtonsView : UIViewController
    • 2.我究竟应该如何使用方法“- (void)tabBar:(UITabBar *)...”?我应该在我的代码中的另一个方法中的某个地方使用它还是使用“IBAction”来调用它?
    【解决方案2】:

    //禁用此功能

    UITabBarController.tabbar.userInteractionEnabled = NO;
    

    // 启用此功能

    UITabBarController.tabbar.userInteractionEnabled = YES;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-06
      • 2013-02-18
      • 2013-12-08
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多