控制台警告:尝试在演示或解雇过程中从视图控制器中解除

时间:2014-07-14 20:28:01

标签: ios

“警告:正在进行演示或解雇时尝试从视图控制器中解除!”

我正在尝试让我的应用在选择要上传的图片时进入加载屏幕。这可以通过选择图片,删除UIImagePickerController场景,添加加载场景,并在上传完成后删除加载场景。

-(void)uploadMessage{

[self dismissViewControllerAnimated:NO completion:nil];


LoadingViewController *loadView = [[LoadingViewController alloc]initWithNibName:@"LoadView" bundle:nil];

    [self presentViewController:loadView animated:NO completion:^{

    NSData *fileData;
    NSString *fileName;
    NSLog(@"Image");
    fileData = UIImagePNGRepresentation(self.image);
    fileName = @"image.png";


PFFile *file = [PFFile fileWithName:fileName data:fileData];
[self.game setObject:file forKey:@"picture"];
[self.game saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if(succeeded){
     [self removeAndChangeButtons];
        [self dismissViewControllerAnimated:NO completion:nil];

    }

    }];
}];

}

2 个答案:

答案 0 :(得分:0)

如果成功,您将在方法中解除两次ViewController。显然,这是不可能做到的。我不知道你想要实现什么,但我认为删除第一个[self dismissViewControllerAnimated:NO completion:nil]就可以了。

答案 1 :(得分:0)

您可以使用MBProgressHUD添加功能。

- (void) showMessage:(NSString*)message withTitle:(NSString*)title onView:(UIView*)view removeAfter:(NSTimeInterval)delay{

dispatch_async(dispatch_get_main_queue(), ^{

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    // Configure for text only and offset down
    hud.mode = MBProgressHUDModeText;
    hud.labelText = title;

    hud.detailsLabelText = message;
    hud.margin = 10.f;
    hud.yOffset = 0.0f;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:delay];

});

}

然后在代码中启动后台任务时,调用showMessage,然后完成上传,将其删除。