我如何設置某種觸摸事件爲我的UITabBarItem
?觸摸事件UITabBar或更確切地說UITabBarItem
對於按鈕有buttonname.TouchUpInside
,但我需要使用什麼UITabBarItem
?
我的情況:
我有上有一個UITabBar
一個UIView
。我現在想在用戶碰到UITabBarItems
之一時做些事情。
我如何設置某種觸摸事件爲我的UITabBarItem
?觸摸事件UITabBar或更確切地說UITabBarItem
對於按鈕有buttonname.TouchUpInside
,但我需要使用什麼UITabBarItem
?
我的情況:
我有上有一個UITabBar
一個UIView
。我現在想在用戶碰到UITabBarItems
之一時做些事情。
的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");
}
};
分配標籤值UITabBarItems
並使用此方法對UITabBarItem
訪問觸摸:
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
switch (item.tag) {
case 0:
//
break;
default:
break;
}
}
UITabBar將擁有自己的委託方法,您可以使用哪個項目正在選中。 – Jassi
謝謝SushiHangover和Vishal,這真的很有幫助!我無法將兩個答案都標記爲答案(無論出於何種原因)。但是,謝謝你們! – Reaper