我正在开发一个带有SplitViewController
. 在我的DetailViewController
中,有一个按钮用于呈现QLPreviewController
和显示文档。到目前为止一切正常,但是,当我使用Done
左上角的按钮关闭预览控制器时,应用程序会引发异常并出现以下错误:
*** Assertion failure in -[UIView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2380.17/UIView.m:5781
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after sending -viewDidLayoutSubviews to the view controller. DetailViewController's implementation needs to send -layoutSubviews to the view to invoke auto layout.'
*** First throw call stack: (...)
libc++abi.dylib: terminate called throwing an exception
以下是我如何实现的表示QLPreviewController
及其委托方法:
- (IBAction)previewButtonPressed:(id)sender
{
QLPreviewController *ql = [[QLPreviewController alloc] init];
ql.dataSource = self;
ql.delegate = self;
ql.currentPreviewItemIndex = 0;
[self presentViewController:ql animated:YES completion:NULL];
}
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
return [NSURL fileURLWithPath:self.documentFilePath];
}
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
return 1;
}
和viewDidLayoutSubviews
:
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[self.scrollView setContentSize:self.gridView.frame.size]; // if not called, the contentSize of UIScrollView is wrong.
}
DetailViewController
包含一个UIScrollView
,它有一个自定义UIView
(gridView)作为子视图,gridView 有很多子视图。
在测试时,我注释掉了设置内容大小的代码行,viewDidLayoutSubviews
通过这样做,我可以成功地关闭预览控制器。但是,这仅在我将gridView
其作为子视图添加到scrollView
. 将其添加为子视图后,它会在解雇时再次崩溃。这次我收到EXC_BREAKPOINT
错误并且控制台上没有日志。调试器的输出如下:
CoreFoundation`CFHash:
0x4597740: pushl %ebp
0x4597741: movl %esp, %ebp
0x4597743: pushl %edi
0x4597744: pushl %esi
0x4597745: subl $16, %esp
0x4597748: calll 0x459774d ; CFHash + 13
0x459774d: popl %edi
0x459774e: movl 8(%ebp), %esi
0x4597751: testl %esi, %esi
0x4597753: jne 0x459776b ; CFHash + 43
0x4597755: int3
0x4597756: calll 0x46eca00 ; symbol stub for: getpid <- EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
0x459775b: movl %eax, (%esp)
0x459775e: movl $9, 4(%esp)
0x4597766: calll 0x46eca4e ; symbol stub for: kill
...
请注意,该应用程序面向 iOS 6 并使用自动布局。
我想知道是否有人可以帮助我解决这个问题。提前致谢。