2011-09-21 45 views
0

的方法我有如下的方法:點擊標籤欄項目,並執行在Objective-C

- (IBAction)GoToMyWebsite:(id)sender 
{ 
    [self.window makeKeyAndVisible]; 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:cc.BPS_WEB_ADDRESS]]; 
    exit(0); 
} 

我如何連接這個方法將標籤欄項目? 因此,當我點擊特定的標籤欄項目時,此方法將被執行。

感謝

UPDATE

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { NSLog(@"didSelectItem: %d", item.tag); } 

回答

1

只要把它在viewDidLoad/viewWillAppear方法。或者,如果您設置了UITabBar的代表,則可以使用代理方法

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item

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

+0

請檢查下更新代碼,切換標籤欄,它的任何想法時,沒有發生?謝謝 –

+1

'self.tabbarController.delegate = self;' –