Reputation: 99
I want to be able to change the right navigation bar button to a different button with name and action.
As an Example:
btnOpenImage is pressed and rightNavButton1 changes to rightNavButton2
Upvotes: 2
Views: 832
Reputation: 20541
-(IBAction) btnOpenImage_Clicked:(id)sender{
//1. IF buttons are UIBarButtonItem then use bellow code
// This bellow line for Change the action(Target)
[rightNavButton1 setAction:@selector(rightNavButton2_Clicked)];
//This bellow line For Change the Title
[rightNavButton1 setTitle:@"rightNavButton2_Clicked"];
//OR 2. IF buttons are UIButton then use bellow code
// This bellow line for Change the action(Target)
[rightNavButton1 addTarget:self action:@selector(rightNavButton2_Clicked) forControlEvents:UIControlEventTouchUpInside];
//This bellow line For Change the Title
[rightNavButton1 setTitle: @"rightNavButton2" forState: UIControlStateNormal];
}
Upvotes: 2
Reputation: 6218
Try this:
[btnOpenImage addTarget:self
action:@selector(aMethod)
forControlEvents:UIControlEventTouchDown];
- (void)aMethod
{
[rightNavButton1 setTitle: @"rightNavButton2" forState: UIControlStateNormal];
}
Upvotes: 1