[iOS] [Objective-c] imagepicker到下一个控制器

时间:2016-02-18 11:10:58

标签: ios objective-c uiimagepickercontroller

- (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'

UPDATE 我将uiimagepickercontroller方法移动到下一个控制器

1 个答案:

答案 0 :(得分:0)

您的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];
        }
    }];
}