我有一些代码可以在导航控制器中构建和显示viewController。第一次通过handleDoubleTapRecognizer
一切都按预期工作。但是,此后每次触发handleDoubleTapRecognizer
时,handleDoubleTapRecognizer
内置的导航控制器及其内容控制器都不会出现,而是在控制台中收到这条令人愉快的消息......
Warning: Attempt to present <UINavigationController: 0x7bbafa00> on <iRpImageViewerViewController: 0x80164580> whose view is not in the window hierarchy!
另请注意,[self.view superview]返回nil,因此某些东西完全破坏了从该视图到其父视图的连接。
...
@implementation iRpImageViewerViewController
{
IGGridView *theMainImageGridviewControl;
iRpImageSet *thePropertyImageSet;
iRpImageFilmstripViewController *theFilmstripViewController;
iRpImageAndMedia *initialMediaItem; // The item to display when first loaded.
UIImageView *primaryImageMarker;
UINavigationController *imageEditorNavController;
iRpImageEditorViewController *imageEditorVC;
}
...
-(void)handleDoubleTapRecognizer:(UITapGestureRecognizer*)recognizer
{
NSLog(@"Double Tapped on ImageViewerViewController's main image, 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];
}