set up an action with a tab bar item - iphone

后端 未结 3 1126
感情败类
感情败类 2020-12-06 14:06

I don\'t no if this is possible, but this there a way to treat a tab bar item click like a regular button click(action)? Here\'s the reason: I have a tab bar in my applicati

3条回答
  •  醉话见心
    2020-12-06 14:25

    The most straightforward way is the UITabBarDelegate. Sorry. Implement your class and inherit the protocol by adding after your class definition e.g.:

    @interface MyViewController : UIViewController
    

    and then define the method tabBar:didSelectItem: in that class e.g.

    - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
        // Do Stuff!
        // if(item.title == @"First") {...}
    }
    

    Then set the delegate on your tabbar like so: myTabBar.delegate = myClassInstance. The tabBar:didSelectItem: method can be anywhere including your view controller and is where you will get the event that the button was clicked. More info here:

    http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITabBarDelegate_Protocol/Reference/Reference.html

提交回复
热议问题