【问题标题】:How can i get Tabbar Item Button's Click event by clicking on TabbarItem button?如何通过单击 TabbarItem 按钮获取 Tabbar 项按钮的 Click 事件?
【发布时间】:2016-07-22 18:23:13
【问题描述】:

我已经使用了 UITabbar,因为我使用了两个按钮作为 TabItem。我想通过单击这两个按钮来执行两个不同的操作,那么如何在单击特定的 Tabbar 按钮时获得特定的操作。

【问题讨论】:

    标签: iphone


    【解决方案1】:

    您很可能希望利用 UITabBarControllerDelegate,然后处理 didSelectViewController 方法。

    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    

    更多详情请看这里:http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html

    【讨论】:

      【解决方案2】:
      -(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
      {
          if(item.tag==1)
          {
              //your code
          }
          else
          {
             //your code
          }
      }
      

      您可以使用UITabBarDelegate 来跟踪按下哪个按钮,方法是将tagtitle 分配给title,您可以使用item.title

      【讨论】:

      • 此解决方案适用于您不使用实际的 TabBarController 并且只是想在普通视图控制器中捕获一些标签栏点击事件的情况。谢谢!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-25
      • 2015-04-19
      • 1970-01-01
      • 2016-02-13
      相关资源
      最近更新 更多