简体   繁体   English

创建未知类型的图像格式是错误的(lldb)

[英]Creating an image format with an unknown type is an error (lldb)

I'm developing an app and it has two image views. 我正在开发一个应用程序,它有两个图像视图。 Each image view has its own button to select image from camera roll. 每个图像视图都有其自己的按钮,用于从相机胶卷中选择图像。 When I click the button one it shows a camera roll and I select an image and it is displayed in the image view1 but when I click the second button to select image from camera roll and select image, it shows the image on the image view1 instead of imageview2. 当我单击一个按钮时,它显示了一个相机胶卷,我选择了一个图像,它显示在图像视图1中,但是当我单击第二个按钮以从相机胶卷中选择图像并选择图像时,它改为在图像视图1中显示图像。 imageview2。 Does anyone know how to solve it???.This is my interface. 有人知道如何解决吗?。。这是我的界面。 I'm using Objective-c language. 我正在使用Objective-c语言。

在此处输入图片说明

here is the code : 这是代码:

- (IBAction)CNICFront:(id)sender { 
    picker = [[UIImagePickerController alloc]init]; 
    picker.delegate=self; 
    [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]‌​;
    [self presentViewController:picker animated:YES completion:NULL]; 
} 

- (IBAction)CNICBack:(id)sender { 
    pic = [[UIImagePickerController alloc]init]; 
    pic.delegate=self; 
    pic setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]‌​; 
   [self presentViewController:pic animated:YES completion:NULL]; 
} 

Delegate methods are for image view 1 is this: - 图像视图1的代表方法是这样的:-

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ 
     image=[info objectForKey:@"UIImagePickerControllerOriginalImage"];
     [self.imageView1 setImage:image]; 
     [self dismissViewControllerAnimated:YES completion:NULL]; 
 }

 -(void)imagePickerControllerDidCancel:(UIImagePickerControll‌​er *)picker{ 
     [self dismissViewControllerAnimated:YES completion:NULL]; 
 } 

在此处输入图片说明 updated Code: example 更新的代码:示例

.h file: .h文件:

@property (weak, nonatomic) IBOutlet UIImageView *img1;
@property (weak, nonatomic) IBOutlet UIImageView *img2;
- (IBAction)but1:(UIButton *)sender;
- (IBAction)but2:(UIButton *)sender;

.m File file .m文件文件

    #import "ViewController.h"

    @interface ViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>{
        UIImagePickerController *picker;
        NSString *ImageViewC;
    }

    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
   picker = [[UIImagePickerController alloc]init];
    picker.delegate=self;


    }


    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }


    - (IBAction)but1:(UIButton *)sender {
        ImageViewC=@"1";

        [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        [self presentViewController:picker animated:YES completion:NULL];

    }

    - (IBAction)but2:(UIButton *)sender {
        ImageViewC=@"2";

        [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        [self presentViewController:picker animated:YES completion:NULL];

    }

    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{

        UIImage * image=[info objectForKey:@"UIImagePickerControllerOriginalImage"];
        if ([ImageViewC isEqualToString:@"1"]) {
            [self.img1 setImage:image];
        }else{
            [self.img2 setImage:image];
        }
        [self dismissViewControllerAnimated:YES completion:NULL];
    }

    -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
        [self dismissViewControllerAnimated:YES completion:NULL];

    }
    @end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM