UIDocumentMenuViewController在iPad上崩溃,但不在iPhone上

演示一个UIDocumentMenuViewController ,以便能够将文件加载到应用程序中。 在iPhone上,它的作品,但不是在iPad上。 使用iOS9。 任何想法是什么错误?

 dmvc = UIDocumentMenuViewController(documentTypes: ["public.data"], inMode: .Import) dmvc!.delegate = self dmvc!.popoverPresentationController?.sourceView = addSongButton self.presentViewController(dmvc!, animated: true, completion: nil) 

2016-06-07 09:45:45.256记住[2994:977408] UICollectionViewFlowLayout的行为没有定义,因为:2016-06-07 09:45:45.260记住[2994:977408]物品宽度必须小于UICollectionView的宽度减去左侧和右侧的值,减去内容左右值。 2016-06-07 09:45:45.261记住[2994:977408]相关的UICollectionViewFlowLayout实例是<_UIAlertControllerCollectionViewFlowLayout:0x1668e6e0>,它被附加到; animation= {bounds.origin =; bounds.size =; 位置=; }; 层=; contentOffset:{0,0}; contentSize:{0,0}>集合视图布局:<_UIAlertControllerCollectionViewFlowLayout:0x1668e6e0>。 2016-06-07 09:45:45.262记住[2994:977408]在UICollectionViewFlowLayoutBreakForInvalidSizes中创build一个符号断点,以在debugging器中捕获这个断点。

我不明白为什么错误消息引用collectionView ? 我根本不使用collectionView。 也许UIDocumentMenuViewController有它作为内部组件?

iPad有一些关于ActionSheets及其取消button的特殊规则,通常取决于你在哪里显示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) 

我有同样的问题。 我设置了sourceView = self.view,并且必须创build一个sourceRect = theButton.frame。