私のアプリには4つのUIButtonがあり、これらはすべて4つのUIAlerViewに接続されているため、ボタンを押すとUIAlertViewがポップアップ表示されます。これは、すべてのUIButtonで正常に機能します。UIAlertViewのオプションの1つは、ユーザーが各UIButtonに接続されている4つのUIImageViewの画像を変更できるように、フォトライブラリを開く必要があります。問題は、UIButtonから画像を選択すると、その写真が1つのImageView、つまり4番目の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