我希望能够将右侧导航栏按钮更改为具有名称和操作的其他按钮。
作为例子:
按下btnOpenImage并将rightNavButton1更改为rightNavButton2
答案 0 :(得分:2)
-(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];
}
答案 1 :(得分:1)
试试这个:
[btnOpenImage addTarget:self
action:@selector(aMethod)
forControlEvents:UIControlEventTouchDown];
- (void)aMethod
{
[rightNavButton1 setTitle: @"rightNavButton2" forState: UIControlStateNormal];
}