我正在开发一个应用程序,它有两个图像视图。每个图像视图都有自己的按钮来从相机胶卷中选择图像。当我点击一个按钮时,它会显示一个相机胶卷,我选择一个图像并显示在图像视图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