【发布时间】:2014-12-18 18:19:26
【问题描述】:
我在从 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?
【问题讨论】:
-
遗憾的是,这不是一个答案,但值得一提的是,Apple 的 Lister 示例代码(Swift 变体)在 iOS 8.1 + Xcode 6.1 上一直向我发出非常相似的警告
-
objective-c 版本也是如此。估计是内部问题我将我的更新推送到了 App Store,到目前为止似乎没有人抱怨这个问题。
标签: ipad uikit autolayout icloud uialertcontroller