0

我对 X Code 比较陌生,我正在开发照片拼贴应用程序,当我从一个选择器中选择图像时,图像选择器工作正常,但我想从不同的图像选择器中选择不同的图像,然后图像选择器无法正常工作

任何人都可以帮我解决我的问题。这是我的代码

`

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


}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    [picker dismissModalViewControllerAnimated:YES];
    imagepicker.view.hidden=YES;


        photoPreviewImageView.image=image;


}
-(void)imagePickerController1:(UIImagePickerController *)picker1 didFinishPickingImage:(UIImage *)image1 editingInfo:(NSDictionary *)editingInfo1
{
    [picker1 dismissModalViewControllerAnimated:YES];
    imagepicker.view.hidden=YES;
             photoPreviewImageView1.image=image1;

}

`

4

3 回答 3

1
//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;
}

试试这个希望它会帮助你

于 2012-06-13T07:44:43.347 回答
0

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

于 2012-06-13T07:24:09.433 回答
0

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

您应该在 imagePicker 实例上创建并根据您需要更改的图像更改其标签,然后在-didFinishPickingImage检查中if (picker.tag == SOME_TAG)然后适当设置。

于 2012-06-13T07:41:22.187 回答