我试图用 4 个 ImageViews 和 4 个 UIButtons 做一个应用程序。当按下其中一个 UIButtons 时,应显示 UIAlertView 并带有 3 个选项。一个名为“图片”的应该打开照片库,以便用户可以更改 ImageView 图片。我为此编写了一个代码,但它不会工作。有人对如何使它工作有任何建议吗?提前致谢!
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
NSString *buttonOne = changeButtonOne; //the UIButtons
NSString *buttonTwo = changeButtonTwo;
NSString *buttonThree = changeButtonThree;
NSString *buttonFour = changeButtonFour;
if([buttonOne isEqualToString:@"buttonOne"])
{
if([title isEqualToString:@"Done"])
{
NSLog(@"You pressed done");
}
else if([title isEqualToString:@"Phone number"])
{
NSLog(@"You pressed Phone number");
}
else if([title isEqualToString:@"Picture"])
{
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];
}
}
else if([buttonTwo isEqualToString:@"buttonTwo"])
{
if([title isEqualToString:@"Done"])
{
NSLog(@"Yoy pressed done");
}
else if([title isEqualToString:@"Phone number"])
{
NSLog(@"You pressed Phone number");
}
else if([title isEqualToString:@"Picture"])
{
imagePickerController2 = [[UIImagePickerController alloc]init]; //I think its the part thats wrong.
[imagePickerController2 setDelegate:self];
[imagePickerController2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController2 animated:YES completion:nil];
}
}
else if([buttonThree isEqualToString:@"buttonThree"])
{
if([title isEqualToString:@"Done"])
{
NSLog(@"You pressed done");
}
else if([title isEqualToString:@"Phone number"])
{
NSLog(@"You pressed Phone number");
}
else if([title isEqualToString:@"Picture"])
{
imagePickerController3 = [[UIImagePickerController alloc]init]; //i think this is the wrong part
[imagePickerController3 setDelegate:self];
[imagePickerController3 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController3 animated:YES completion:nil];
}
}
else if([buttonFour isEqualToString:@"buttonFour"])
{
if([title isEqualToString:@"Done"])
{
NSLog(@"You pressed done");
}
else if([title isEqualToString:@"Phone number"])
{
NSLog(@"You pressed Phone number");
}
else if([title isEqualToString:@"Picture"])
{
imagePickerController4 = [[UIImagePickerController alloc]init]; //this is probably the wrong part
[imagePickerController4 setDelegate:self];
[imagePickerController4 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController4 animated:YES completion:nil];
}
}
}
@end