2016-07-29 42 views
2

我如何設置某種觸摸事件爲我的UITabBarItem觸摸事件UITabBar或更確切地說UITabBarItem

對於按鈕有buttonname.TouchUpInside,但我需要使用什麼UITabBarItem

我的情況:

我有上有一個UITabBar一個UIView。我現在想在用戶碰到UITabBarItems之一時做些事情。

+0

UITabBar將擁有自己的委託方法,您可以使用哪個項目正在選中。 – Jassi

+0

謝謝SushiHangover和Vishal,這真的很有幫助!我無法將兩個答案都標記爲答案(無論出於何種原因)。但是,謝謝你們! – Reaper

回答

2

UITabBar本身響應觸摸,然後你看看UITabBarItemEventArgs.Item因爲這是在選擇項目的明細標籤欄並根據需要進行響應:

var tabBar = new UITabBar(); 
tabBar.ItemSelected += (object sender, UITabBarItemEventArgs e) => 
{ 
    Console.WriteLine($"{e.Item} has selected"); 
    if (e.Item.Tag == 99) 
    { 
     Console.WriteLine("Item with tag 99 was selected"); 
    } 
}; 
1

分配標籤值UITabBarItems並使用此方法對UITabBarItem訪問觸摸:

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item 
{ 
    switch (item.tag) { 
     case 0: 
      // 
      break; 

     default: 
      break; 
    } 
}