我有 2 个 uiimage 视图(imageview 和 imageview2)和 2 个 uibuttons(useCameraRoll 和 useCameraRoll2) 我已经实现了使用 2 个按钮在这些视图上设置图像的代码。
imageview 与它的按钮 useCameraRoll 一起工作正常,但是当我使用 useCameraRoll2 设置图像时,它会更改 imageview 而不是 imageview2 的图像。
视图/按钮 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
}
}
我检查了界面生成器中的所有连接是否都连接到正确的视图。
有谁知道为什么会出错
问候