1

我有一个看起来像这样的故事板:

故事板

它是这样工作的:在其 .m 文件中InitialSlidingViewController实例化 Navigation VC,topViewController如下所示:

 -(void)viewDidLoad {
  [super viewDidLoad];

  self.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Navigation"];

}

在 Navigation VC 被实例化后,它会创建底层 Menu 并将其设置为 underLeftVC。这是使用ECSlidingViewController。这将创建一个使用平移手势的滑动菜单,类似于 Facebook。

NavigationVC 的 rootVC 是我的 ItemsCDTVC。当我单击 + 按钮时,它会弹出一个操作表,允许我从相机拍摄照片或从照片库中选择。但是,然后我希望它模态地转到 ManageItemVC 并将我刚刚选择/拍摄的图片设置为它的 UIImageView。当我尝试呈现时,它会引发以下错误:

Warning: Attempt to present <ManageItemViewController: 0x81d52a0> on <InitialSlidingViewController: 0x8122ce0> whose view is not in the window hierarchy!

这是真的,因为 InitialSlidingVC 不在屏幕上,而 ItemCDTVC 是,但我该如何解决这个问题?

我已经在我的 Storyboard 中使用底部灵活空间的标识符设置了模态类型转场(当点击时,它没有做任何事情,所以我选择它来创建视觉转场)。这是我在 ItemCDTVC 中的 segue 代码:

 -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // let's get the edited image
    UIImage *image = info[UIImagePickerControllerEditedImage];
    // but if for some reason we disable editing in the future, this is our safeguard
    if(!image) image = info[UIImagePickerControllerOriginalImage];
    if(image) {
        self.pictureImageView.image = image;
        [self performSegueWithIdentifier:@"addItemSegue" sender:self];
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([segue.identifier isEqualToString:@"addItemSegue"]){
        ManageItemViewController *manageItemVC = (ManageItemViewController *)[segue destinationViewController];
        manageItemVC.pictureImageView = self.pictureImageView;
    }
}

尝试呈现模态 VC 时失败。

4

1 回答 1

5

已修复,我唯一要做的就是在尝试执行 segue 之前关闭 imagePickerController,如下所示:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // let's get the edited image
    UIImage *image = info[UIImagePickerControllerEditedImage];
    // but if for some reason we disable editing in the future, this is our safeguard
    if(!image) image = info[UIImagePickerControllerOriginalImage];
    if(image) {
        self.pictureImage = image;
        [self dismissViewControllerAnimated:NO completion:^{
            [self performSegueWithIdentifier:@"addItemSegue" sender:self];
        }];
    }
}
于 2013-05-09T19:43:43.547 回答