Reputation: 760
How can i set up some kind of touch event for my UITabBarItem
?
For Buttons there's buttonname.TouchUpInside
, but what do i need to use for the UITabBarItem
?
My situation:
I have a UIView
with a UITabBar
on it. I now want to do stuff when the user touches one of the UITabBarItems
.
Upvotes: 3
Views: 1206
Reputation: 74184
The UITabBar
itself responds to touches and then you look at the UITabBarItemEventArgs.Item
for the details of the item that was selected in the tab bar and react as needed:
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");
}
};
Upvotes: 3
Reputation: 2693
Assign tag value to UITabBarItems
and use this method for accessing touch on UITabBarItem
:
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
switch (item.tag) {
case 0:
//
break;
default:
break;
}
}
Upvotes: 1