Reaper
Reaper

Reputation: 760

Touch event for UITabBar or rather UITabBarItem

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

Answers (2)

SushiHangover
SushiHangover

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

Vishal Sonawane
Vishal Sonawane

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

Related Questions