有关如何诊断视图控制器丢失对父视图控制器的引用的提示

时间:2016-04-19 23:47:07

标签: ios objective-c lldb

我有一个类someViewController,在其中一个视图上有一个手势识别器,双击触发该手势的处理程序,然后创建并抛出一个包装iRpImageViewerViewController的UINavigationController。 p>

iRpImageViewerViewController是UINavigationController中的唯一内容控制器。我有一个NSLog语句,在给定的点上显示以下结果。

<iRpImageViewerViewController: 0x84689690>'s parentViewController is <UINavigationController: 0x7ca31800>

然后在某个时候,我做双击手势,再次触发该代码,我的NSLog语句记录此消息。

<iRpImageViewerViewController: 0x84689690>'s parentViewController is (null)

UINavigationControllers内容控制器如何在地球上失去与包含UINavigationController的连接。我没有做任何神秘或奇怪的事情,尝试引用或使用内容控制器,手动维护它的生命周期。

同样在日志中,我没有放在那里,这是一个令人不安的小故障......

Warning: Attempt to present <UINavigationController: 0x7e98ee00> on <iRpImageViewerViewController: 0x84689690> whose view is not in the window hierarchy!

不知怎的,在某个地方,iRpImageViewerViewController失去了对它的parentViewController的引用,而它的presentViewController ......都是零。

是否有LLDB技术来确定这种情况究竟发生在哪里?

以下代码中使用了以下2个变量

@implementation someViewController
{
    UINavigationController *imageEditorNavController;
    iRpImageEditorViewController *imageEditorVC;
}

然后在该课程中进一步向下,我的演示文稿代码在此处,当用户双击iRpImageViewerViewController

中的视图时触发
-(void)handleDoubleTapRecognizer:(UITapGestureRecognizer*)recognizer
    {
        NSLog(@"Double Tapped, so opening editor");
        IGCellPath *pathForCurrentCell = [self pathForCurrentCell];
        iRpImageAndMedia *imageAndMediaItem = [thePropertyImageSet objectAtIndex:pathForCurrentCell.columnIndex];
        imageEditorVC = [[iRpImageEditorViewController alloc] initWithImageAndMediaItem:imageAndMediaItem];

        imageEditorVC.navigationItem.title = @"Photo Details Editor";
        imageEditorVC.edgesForExtendedLayout = UIRectEdgeNone;

        imageEditorNavController = [[UINavigationController alloc] initWithRootViewController:imageEditorVC];
        imageEditorNavController.modalPresentationStyle = UIModalPresentationFormSheet;
        imageEditorNavController.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(imageEditorDone)];
        imageEditorNavController.topViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(imageEditorCancelled)];
        imageEditorNavController.preferredContentSize = imageEditorVC.view.frame.size;

        NSLog(@"%@'s parentViewController is %@",self, self.parentViewController);

        [self presentViewController:imageEditorNavController animated:YES completion:^(void){ }];

    }

-(void)imageEditorDone
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }


-(void)imageEditorCancelled
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }

0 个答案:

没有答案