UIimage不显示重复方法的图像

时间:2014-10-06 22:22:17

标签: ios objective-c xcode uiimageview duplicates

我有一个打开的UImage视图,你可以用它拍照并在uiimageview中查看它。但我添加了另一个图像视图并复制了代码,现在图像显示的图像与第二个图像相同。我相信它可能与'[UIImagePickerControllerOriginalImage]有关;'

  - (void)imagePickerController:(UIImagePickerController *)
picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissViewControllerAnimated:YES completion:nil];

    // Get the image and store it in the image view
    image = info[UIImagePickerControllerOriginalImage];
    self.personimgThumbNail.image = image;

}

- (void)imagePickerControllertwo:(UIImagePickerController *)
picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissViewControllerAnimated:YES completion:nil];

    // Get the image and store it in the image view
    imagetwo = info[UIImagePickerControllerOriginalImage];
    self.personimgThumbNailtwo.image = imagetwo;

}

只需要下一步,已经坚持了很长一段时间。

1 个答案:

答案 0 :(得分:1)

只有一个didFinish-Method。您必须区分方法本身内部的操作。该方法已经为您提供了UIImagePickerController,它正在调用该方法,因此您只需要比较指向它的指针。

 - (void)imagePickerController:(UIImagePickerController *)
picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
     [self dismissViewControllerAnimated:YES completion:nil];

     if(picker == self.pickerController1){
        // Get the image and store it in the image view
        image = info[UIImagePickerControllerOriginalImage];
        self.personimgThumbNail.image = image;
    }else if(picker == self.pickerController2){
        // Get the image and store it in the image view
        imagetwo = info[UIImagePickerControllerOriginalImage];
        self.personimgThumbNailtwo.image = imagetwo;
    }
}

编辑:您必须在班级的.m文件中定义2个属性

@property (strong) UIImagePickerController *pickerController1;
@property (strong) UIImagePickerController *pickerController2;

当您实例化图像选择器时,您现在需要做的是以下内容 (代码取自本答复的OP评论)

- (IBAction)accessPhotoLibrary:(id)sender {
    if(!self.pickerController1){
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
        imagePicker.delegate = self; 
        self.pickerController1 = imagePicker;
    }
    [self presentViewController:self.pickerController1 animated:YES completion:nil]; 
}