簡體   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