I need to retrieve when a user click over a tabbaritem into a uitabbarcontroller to change something.. here is my code:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    if (item == [tabBarController.tabBar.items objectAtIndex:2]) {
        item.title = @"add shot";
    }
    else
    {
        item.title = @"Race";
    }
}
but If I do this:
self.tabBarController.tabBar.delegate = self;
i receive a sigkill...
what's the right solution? thanks in advance
Does your view controller conform to the UITabBarDelegate protocol? In the header file:
@interface MyViewController : UIViewController<UITabBarDelegate> {
    // ...
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;
@end
Then, just do:
tabBar.delegate = self;
Instead of:
self.tabBarController.tabBar.delegate = self;
And:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    //self.tabBarItem.title = @"Title";
}
                        I came across this answer while learning iOS development, But I wanted to include the little missing pieces for n00bs like me.
// HelloWorldViewController.h
@interface HelloWorldViewController : UIViewController <UITabBarDelegate>
{   
}
@property (weak, nonatomic) IBOutlet UITabBar *tabBar;    
@end
And
// HelloWorldViewController.m
@interface HelloWorldViewController ()
@end
@implementation HelloWorldViewController 
@synthesize tabBar;
- (void) viewDidLoad
{ 
   tabBar.delegate = self;
}
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
      NSLog(@"didSelectItem: %d", item.tag);
}
@end
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With