在iPad上显示的UIDocumentMenuViewController提供“无法同时满足约束”

时间:2014-10-23 05:52:01

标签: ipad uikit autolayout icloud uialertcontroller

我在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?

2 个答案:

答案 0 :(得分:3)

iPad有一些关于ActionSheets及其取消按钮的特殊规则,它通常取决于您显示ActionSheets的位置,因此您可以通过以下方式解决崩溃问题:

let importMenu = UIDocumentMenuViewController(documentTypes: [kUTTypeHTML as String ], in: .import)
importMenu.delegate = self
importMenu.modalPresentationStyle = .popover
importMenu.popoverPresentationController?.sourceView = self.view
self.present(importMenu, animated: true, completion: nil)

答案 1 :(得分:2)

尝试在展示documentMenu之前添加它:

[documentMenu.view setTranslatesAutoresizingMaskIntoConstraints:NO];