在我的应用程序中有 4 个 UIButtons,它们都连接到 4 个 UIAlerView,因此当按下按钮时,应该会弹出 UIAlertView。这适用于所有 UIButton。UIAlertView 中的选项之一应该打开照片库,以便用户可以更改连接到每个 UIButton 的 4 个 UIImageView 的图片。问题是,当我从任何 UIButtons 中选择图片时,该照片仅适用于一个 ImageView,即第四个。这是我的 UIAlertView 代码:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
//UIAlertView´s in the UIButtons setup
if (alertView.tag == 1) { //button1
if (buttonIndex == alertView.cancelButtonIndex) {
NSLog(@"Done");
}
if (buttonIndex == alertView.firstOtherButtonIndex) {
NSLog(@"Number");
}
if (buttonIndex == alertView.firstOtherButtonIndex+1) {
imagePickerController = [[UIImagePickerController alloc]init]; //I think its this part which are wrong
[imagePickerController setDelegate:self];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController animated:YES completion:nil];
}
}
if (alertView.tag == 2) { //button2
if (buttonIndex == alertView.cancelButtonIndex) {
NSLog(@"Done");
}
if (buttonIndex == alertView.firstOtherButtonIndex) {
NSLog(@"Number");
}
if (buttonIndex == alertView.firstOtherButtonIndex+1) {
imagePickerController = [[UIImagePickerController alloc]init]; //I think its this part which are wrong
[imagePickerController setDelegate:self];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController animated:YES completion:nil];
}
}
if (alertView.tag == 3)
{
if (buttonIndex == alertView.cancelButtonIndex) {
NSLog(@"Done");
}
if (buttonIndex == alertView.firstOtherButtonIndex){
NSLog(@"Number");
}
if (buttonIndex == alertView.firstOtherButtonIndex+1){
imagePickerController = [[UIImagePickerController alloc]init]; //I think its this part which are wrong
[imagePickerController setDelegate:self];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController animated:YES completion:nil];
}
}
if (alertView.tag == 4);
{
if (buttonIndex == alertView.cancelButtonIndex){
NSLog(@"Done");
}
if (buttonIndex == alertView.firstOtherButtonIndex){
NSLog(@"phone number");
}
if (buttonIndex == alertView.firstOtherButtonIndex+1){
imagePickerController = [[UIImagePickerController alloc]init];
[imagePickerController setDelegate:self];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController animated:YES completion:nil];
}
}
}
@end