2 つの uiimage ビュー (imageview & imageview2) と 2 つの uibuttons (useCameraRoll & useCameraRoll2) があり、2 つのボタンを使用してこれらのビューに画像を設定するコードを実装しました。
imageview はそのボタン useCameraRoll と一緒に正常に動作しますが、useCameraRoll2 を使用して画像を設定すると、imageview2 ではなく imageview の画像が変更されます。
ビュー/ボタン 1 のコード:
- (IBAction) useCameraRoll: (id)sender
{
if ([self.popoverController isPopoverVisible]) {
[self.popoverController dismissPopoverAnimated:YES];
} else {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
self.popoverController.delegate = self;
[self.popoverController presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
newMedia = NO;
}
}
}
#pragma mark -
#pragma mark UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self.popoverController dismissPopoverAnimated:true];
NSString *mediaType = [info
objectForKey:UIImagePickerControllerMediaType];
// [self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info
objectForKey:UIImagePickerControllerOriginalImage];
self.imageView.image = image;
if (newMedia)
UIImageWriteToSavedPhotosAlbum(image,
self,
@selector(image:finishedSavingWithError:contextInfo:),
nil);
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}
}
ビュー/ボタン 2 のコード:
- (IBAction) useCameraRoll2: (id)sender
{
if ([self.popoverController2 isPopoverVisible]) {
[self.popoverController2 dismissPopoverAnimated:YES];
} else {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker2 =
[[UIImagePickerController alloc] init];
imagePicker2.delegate = self;
imagePicker2.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker2.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker2.allowsEditing = NO;
self.popoverController2 = [[UIPopoverController alloc]
initWithContentViewController:imagePicker2];
self.popoverController2.delegate = self;
[self.popoverController2 presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
newMedia = NO;
}
}
}
#pragma mark -
#pragma mark UIImagePickerControllerDelegate
-(void)imagePickerController2:(UIImagePickerController *)picker2
didFinishPickingMediaWithInfo:(NSDictionary *)info2
{
[self.popoverController2 dismissPopoverAnimated:true];
NSString *mediaType2 = [info2
objectForKey:UIImagePickerControllerMediaType];
// [self dismissModalViewControllerAnimated:YES];
if ([mediaType2 isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image2 = [info2
objectForKey:UIImagePickerControllerOriginalImage];
self.imageView2.image = image2;
if (newMedia2)
UIImageWriteToSavedPhotosAlbum(image2,
self,
@selector(image:finishedSavingWithError:contextInfo:),
nil);
}
else if ([mediaType2 isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}
}
インターフェイスビルダーのすべての接続が正しいビューに接続されていることを確認しました。
なぜこれがうまくいかないのか誰かが知っていますか
よろしく