UIPickerView UIImage和Segue

时间:2014-06-11 13:46:58

标签: ios objective-c uiimage uipickerview

在我的应用中,我在UserView中使用带有UIImagePickerCollection的相机。但是一旦用户选择“使用照片”,我想将我的照片放在另一个视图中,即“cameraView”,因为我有一些治疗方法。这是我的代码:

-(void)takeAPicture{
NSLog(@"CHEESE");
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];

imagePicker.delegate = self;

imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;

imagePicker.mediaTypes =
@[(NSString *) kUTTypeImage];

imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker
                   animated:YES completion:nil];
}

-(void)imagePickerController:
(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissViewControllerAnimated:YES completion:^{
    _img = [info objectForKey:UIImagePickerControllerOriginalImage];
    if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
        UIImageWriteToSavedPhotosAlbum(_img, nil, nil, nil);
    }}];
    [self performSegueWithIdentifier:@"toCameraView" sender:self];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"toCameraView"])
        {
            CameraViewController *transferViewController = segue.destinationViewController;
        transferViewController.img = _img;
    }
}

当我运行我的应用程序时,我收到一条警告消息:

Warning: Attempt to present <CameraViewController: 0x17e20eb0> on <EIUserViewController: 0x189b1000> while a presentation is in progress!

我不明白它是什么,以及如何处理它,我无法设法在另一个视图中接收我的图像并在选择“使用图片”后直接显示我的视图。如果有人有解释或解决方案?谢谢你们!

2 个答案:

答案 0 :(得分:1)

你正试图在UIImagePickerController解雇期间[self performSegueWithIdentifier:@“toCameraView”sender:self],换句话说:无法动画第一个VC消失时出现的第二个VC。 尝试移动[self performSegueWithIdentifier:@“toCameraView”sender:self];在completionBlock内部:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissViewControllerAnimated:YES completion:^{
    _img = [info objectForKey:UIImagePickerControllerOriginalImage];
    if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
        UIImageWriteToSavedPhotosAlbum(_img, nil, nil, nil);
    [self performSegueWithIdentifier:@"toCameraView" sender:self];
    }}];
}

答案 1 :(得分:0)

因此,当imagePicker调用委托方法imagePickerController: didFinishPickingMediaWithInfo:时,viewController仍然会显示imagePicker。

对此的一个解决方案是当你回到viewController时呈现cameraView:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissViewControllerAnimated:YES completion:^{
    _img = [info objectForKey:UIImagePickerControllerOriginalImage];
    if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
        UIImageWriteToSavedPhotosAlbum(_img, nil, nil, nil);
    }}];
    self.newPicture = YES;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    if (self.newPicture) {
        [self performSegueWithIdentifier:@"toCameraView" sender:self];
        self.newPicture = NO;
    }
}

希望有所帮助