我有一个带有它的导航控制器(A)的内容视图控制器(B)和一个带有modalPresentationStyle = UIModalPresentationFormSheet(C)的视图控制器。
嗯,奇怪的是,如果您创建视图并将视图添加到另一个视图,视图控制器就不会像您自己那样维护视图层次结构。
例如,导航控制器(A)在演示时,不会像这样设置(B)...
[self addChildViewController:child];
[self.view addSubview:child.view];
[child didMoveToParentViewController:self];
...因此,如果你试图从(B)中呈现一个视图控制器,调试控制台会抱怨像...这样的消息
Warning: Attempt to present <UINavigationController: 0x79454a00> on <iRpImageViewerViewController: 0x81e4fc00> whose view is not in the window hierarchy!
我知道摆脱该消息的唯一方法是从导航控制器(A)呈现照片细节编辑器导航控制器(C)而不是从(A)的内容视图控制器(B)呈现 - - (A)的孩子
这是正常的,导航控制器会破坏视图链,导致上面的警告消息,或者我只是不明白呈现视图的工作方式,以及您无法正确显示导航控制器(C)来自另一个导航控制器内容控制器(B),但仅来自父导航控制器本身(A)。
显示控制台警告的快捷方法是将此代码段中的最后一行从self.parentViewController
更改为self
-(void)handleDoubleTapRecognizer:(UITapGestureRecognizer*)recognizer
{
NSLog(@"Double Tapped, so opening editor");
IGCellPath *pathForCurrentCell = [self pathForCurrentCell];
iRpImageAndMedia *imageAndMediaItem = [thePropertyImageSet objectAtIndex:pathForCurrentCell.columnIndex];
iRpImageEditorViewController *imageEditor = [[iRpImageEditorViewController alloc] initWithImageAndMediaItem:imageAndMediaItem];
imageEditor.navigationItem.title = @"Photo Details Editor";
imageEditor.edgesForExtendedLayout = UIRectEdgeNone;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:imageEditor];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(imageEditorDone)];
navController.topViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(imageEditorCancelled)];
navController.preferredContentSize = imageEditor.view.frame.size;
[self.parentViewController presentViewController:navController animated:YES completion:^(void){ }];
}