繁体   English   中英

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

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

我正在开发一个应用程序,它有两个图像视图。 每个图像视图都有其自己的按钮,用于从相机胶卷中选择图像。 当我单击一个按钮时,它显示了一个相机胶卷,我选择了一个图像,它显示在图像视图1中,但是当我单击第二个按钮以从相机胶卷中选择图像并选择图像时,它改为在图像视图1中显示图像。 imageview2。 有人知道如何解决吗?。。这是我的界面。 我正在使用Objective-c语言。

在此处输入图片说明

这是代码:

- (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]; 
} 

图像视图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]; 
 } 

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

.h文件:

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

.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