[iOS][Objective-c] 图像选择器到下一个控制器
Posted
技术标签:
【中文标题】[iOS][Objective-c] 图像选择器到下一个控制器【英文标题】:[iOS][Objective-c] imagepicker to next controller 【发布时间】:2016-02-18 11:10:58 【问题描述】:- (IBAction)sendPhoto:(id)sender
[DinsowMiniLogger log:@"Image: %@", self.pickedImage];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
[picker dismissViewControllerAnimated:YES completion:nil];
[[self navigationController] dismissViewControllerAnimated:YES completion:nil];
self.selMediaItem = [self.storyboard instantiateViewControllerWithIdentifier:@"selectmedia"];
[self presentModalViewController:self.selMediaItem animated:YES];
self.selMediaItem.imgMediaSelect.image = [info objectForKey:UIImagePickerControllerOriginalImage];
我想将图像发送到下一个控制器但出错
由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'-[UINavigationController imgMediaSelect]:无法识别的选择器发送到实例 0x15979a00'
更新 我将 uiimagepickercontroller 方法移动到下一个控制器
【问题讨论】:
能否请您说明您在哪里定义了 imgMediaSelect? 只需在下一个视图控制器中定义 UIImage 的属性,然后在此处分配您的图像 self.selMediaItem.imageProperty=[info objectForKey:UIImagePickerControllerOriginalImage];然后你的下一个视图控制器中有图像。 【参考方案1】:您的didFinishPickingMediaWithInfo
方法应如下所示。在执行任何操作之前,您将关闭您的视图。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
UIImage *browsed_Image = [info objectForKey:UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:^
if (browsed_Image)
// You can store here your image in UIImage object or directly pass it to next controller.
[btn_UserImage setImage:browsed_Image forState:UIControlStateNormal];
];
【讨论】:
以上是关于[iOS][Objective-c] 图像选择器到下一个控制器的主要内容,如果未能解决你的问题,请参考以下文章
Swift - 无法识别的选择器到实例 - UITapGestureRecognizer