我正在開發一個應用程序,它有兩個圖像視圖。每個圖像視圖都有自己的按鈕來從相機膠捲中選擇圖像。當我點擊一個按鈕時,它會顯示一個相機膠捲,我選擇一個圖像並顯示在圖像視圖1中,但是當我單擊第二個按鈕從相機膠捲選擇圖像並選擇圖像時,它會在圖像view1上顯示圖像的imageview2。有誰知道如何解決它???這是我的界面。我正在使用Objective-c語言。創建未知類型的圖像格式是錯誤(lldb)
這裏是代碼:
- (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:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:NULL];
}
假設u有2圖像視圖v1和v2 ......在第二回合按鈕動作U設置定圖像v1.image =您的圖像更改爲v2.image =您的圖像。或(從我們的屏幕鏡頭)我認爲你給予同樣的行動2按鈕相同,在這種情況下,你需要使用標籤值你的Takeapic按鈕 –
後您的代碼很容易解決您的問題。 –
- (IBAction)CNICFront:(id)sender {picker = [[UIImagePickerController alloc] init]; picker.delegate = self; [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; [self presentViewController:picker animated:YES completion:NULL]; (IBAction)CNICBack:(id)發送者{= {[UIImagePickerController alloc] init]; pic.delegate = self; [pic setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; [self presentViewController:pic animated:YES completion:NULL]; } – Hamza