我在从 iPad 上的条形按钮项目中显示 UIDocumentMenuViewController 时遇到一些问题。我确实得到了正确的初始行为,并且根据需要从 barButtonItem 调用了菜单,但是在调用委托之前,我收到了一些我不确定如何修复的自动布局约束消息。这就是我调用 UIDocumentMenu VC 的方式:
UIDocumentMenuViewController *documentMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:[self fileUTIList] inMode:UIDocumentPickerModeImport];
documentMenu.delegate = self;
documentMenu.modalPresentationStyle = UIModalPresentationPopover;
documentMenu.popoverPresentationController.barButtonItem = self.rightAddButton;
//documentMenu.popoverPresentationController.sourceView = self.view;
//documentMenu.should have a non-nil sourceView or barButtonItem set before the presentation occurs
[self presentViewController: documentMenu animated:YES completion: ^{
NSLog(@"DocumentPicker presented completion");
}];
我得到上面的完成处理程序被正确调用,它在 iPad 上看起来很好。但是当我为菜单选择一个项目时,我立即收到“无法同时满足约束”消息:
2014-10-22 22:42:20.817 iPad[34421:474588] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7c1d0f30 H:[UIView:0x7c1cbc20(304)]>",
"<NSLayoutConstraint:0x7c1ddbf0 _UIAlertControllerView:0x7c1cbc90.width == UIView:0x7c1ca670.width>",
"<NSLayoutConstraint:0x7c14b310 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7c1ca670(142)]>",
"<NSLayoutConstraint:0x7c151a80 _UIAlertControllerView:0x7c1cbc90.width >= UIView:0x7c1cbc20.width>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7c1d0f30 H:[UIView:0x7c1cbc20(304)]>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2014-10-22 22:42:20.818 iPad[34421:474588] documentMenu: didPickDocumentPicker
然后最终调用了 documentMenu 的委托,并显示了 UIDocumentPickerViewController,看起来是正确的:
- (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker {
NSLog(@"documentMenu: didPickDocumentPicker");
documentPicker.delegate = self;
[self presentViewController:documentPicker animated:YES completion:nil];
但我担心如果我附带这个会产生影响并导致一些奇怪的显示问题。有什么方法可以确定究竟是什么导致了这种行为,因为它似乎来自 UIDocumentMenuViewController / UIAlertControllerView?