Tried this but only works for UIButton:
[btn setTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
Tried this but only works for UIButton:
[btn setTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
Just set the UIBarButtonItem's target
and action
properties directly.
I ran into a similar problem... I assume you mean that if your UIButton is not part of your UITabBar to call btnClicked then it works appropriately. If this is the problem you are proposing then, check your btnClicked method and change it from:
-btnClicked:(id)sender
to
-(void) btnClicked:(id)sender
that, and declare btnClicked in the header file...
For what it's worth, this is how I setup a button in tabbarbuttonitem:
UIBarButtonItem *exampleButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"button.png"] style:UIBarButtonItemStylePlain target:self action:@selector(btnClicked:)];