我正在尝试更改不是发件人的按钮图像,我试图将代码链接到按钮,似乎无法正常工作 我试图将3个按钮链接到 - (IBAction)Button1:(id)发送者;它仍然无效。
·H
-(IBAction)Button1:(id)sender;
-(IBAction)ButtonUn1:(id)sender;
-(IBAction)ButtonDef1:(id)sender;
的.m
-(IBAction)Button1:(id)sender
{
UIImage *btnImage1 = [UIImage imageNamed:@"button_Not_At_all_R.png"];
[sender setImage:btnImage1 forState:UIControlStateNormal];
UIImage *btnImage2 = [UIImage imageNamed:@"Button_Unsure.png"];
UIImage *btnImage3 = [UIImage imageNamed:@"Button_Definitely.png"];
[ButtonUn1 setImage:btnImage2 forState:UIControlStateNormal];
[ButoonDef1 setImage:btnImage3 forState:UIControlStateNormal];
}
感谢您的帮助。
答案 0 :(得分:0)
您需要为按钮创建一个IBOutlet并将其链接以直接访问它:
IBOutlet UIButton* buttonToChangePicture;
IBAction仅用于访问活动。
编辑:
另一种选择是使用viewWithTag。
UIButton* button = (UIButton*)[myView viewWithTag:555]
您需要先为按钮设置一个唯一标记(在我的示例中为555) 没有其他方法可以访问IBAction中的另一个按钮