Iphone 从Dirrent按钮拾取图像时如何调用imagepickerdelegate方法两次

Iphone 从Dirrent按钮拾取图像时如何调用imagepickerdelegate方法两次,iphone,objective-c,image,Iphone,Objective C,Image,我对X代码比较陌生 及 我正在使用照片拼贴应用程序,当我从一个选取器中选取图像时,图像选取器工作正常,但我想从不同的图像选取器中选取不同的图像,图像选取器工作不正常 有人帮我解决问题吗。这是我的密码 ` `UIImagePickerController创建了一个相当重的对象,因此我认为不建议创建多个实例。如果您也这样做,这可能就是导致问题的原因。。如果您也能分享您的代码,这样我们就可以更深入地了解您的问题,那就太好了建议只在图像选择器上使用。从您提供的代码中,您试图创建两个不同的imagepic

我对X代码比较陌生 及 我正在使用照片拼贴应用程序,当我从一个选取器中选取图像时,图像选取器工作正常,但我想从不同的图像选取器中选取不同的图像,图像选取器工作不正常

有人帮我解决问题吗。这是我的密码

`


`

UIImagePickerController
创建了一个相当重的对象,因此我认为不建议创建多个实例。如果您也这样做,这可能就是导致问题的原因。。如果您也能分享您的代码,这样我们就可以更深入地了解您的问题,那就太好了

建议只在图像选择器上使用。从您提供的代码中,您试图创建两个不同的imagepicker委托方法,但实际上两次只调用其中一个

您应该在imagePicker实例上创建,并根据需要更改的图像更改其标记,然后在
-didFinishPickingImage
中选中
如果(picker.tag==SOME_tag)
并进行相应设置

//Take two imageView in your .h file
UIImageView *imgViewForFirstPicker;
UIImageView *imgViewForSecondPicker;

// Alloc these images in view did load 

imgViewForFirstPicker = [[UIImaeView allo] initWithFrame:(give your rect)];

// Similarly for second imageView and add to both in self.view

-(IBAction)imagepickMethod1:(id)sender
{
    UIImagePickerController *imagepicker=[[UIImagePickerController alloc]init];
    imagepicker.delegate=self;

    imagepicker.tag=100;
    imagepicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:imagepicker animated:YES];
}
-(IBAction)imagepickMethod2:(id)sender
{
    UIImagePickerController *imagepicker1=[[UIImagePickerController alloc]init];
    imagepicker1.delegate=self;
    imagepicker1.tag=101;
    imagepicker1.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:imagepicker1 animated:YES];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage: (UIImage*)image editingInfo:(NSDictionary *)editingInfo
{
    [picker dismissModalViewControllerAnimated:YES];
    if(picker.tag == 100)
    imgViewForFirstPicker.image=image;
    else
    imgViewForSecondPicker.image=image;
}

试试这个,希望它能帮助你

请把你的问题说得更清楚,以便我们能帮助你,但在我的应用程序imagepicker.tag中,它不起作用。。你能告诉我怎么解决这个问题吗
//Take two imageView in your .h file
UIImageView *imgViewForFirstPicker;
UIImageView *imgViewForSecondPicker;

// Alloc these images in view did load 

imgViewForFirstPicker = [[UIImaeView allo] initWithFrame:(give your rect)];

// Similarly for second imageView and add to both in self.view

-(IBAction)imagepickMethod1:(id)sender
{
    UIImagePickerController *imagepicker=[[UIImagePickerController alloc]init];
    imagepicker.delegate=self;

    imagepicker.tag=100;
    imagepicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:imagepicker animated:YES];
}
-(IBAction)imagepickMethod2:(id)sender
{
    UIImagePickerController *imagepicker1=[[UIImagePickerController alloc]init];
    imagepicker1.delegate=self;
    imagepicker1.tag=101;
    imagepicker1.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:imagepicker1 animated:YES];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage: (UIImage*)image editingInfo:(NSDictionary *)editingInfo
{
    [picker dismissModalViewControllerAnimated:YES];
    if(picker.tag == 100)
    imgViewForFirstPicker.image=image;
    else
    imgViewForSecondPicker.image=image;
}