【发布时间】:2023-03-29 02:01:02
【问题描述】:
这是问题: 我希望用户点击一个按钮并选择该按钮将代表什么图像。有多个按钮,用户可以选择为他/她点击的每个按钮选择不同的图像或相同的图像。 如何在 void 方法中添加 if 结构来检查按下了哪个按钮?
@implementation ViewController
@synthesize tegelEen,tegelTwee; //tegelEen is a button an so is tegelTwee
-(IBAction)Buttonclicked:(id)sender {
picController = [[UIImagePickerController alloc]init];
picController.delegate = self;
picController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picController animated:YES completion:nil];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *btnImage = [info objectForKey:UIImagePickerControllerOriginalImage];
//Now it changes both buttons but I want it to change only the one that was clicked.
[tegelEen setImage:btnImage forState:UIControlStateNormal];
[tegelTwee setImage:btnImage forState:UIControlStateNormal];
[self dismissViewControllerAnimated:YES completion:nil];
}
提前致谢,是的,我对这种语言很陌生。
【问题讨论】: