UIDocumentMenuViewController crashes on iPad but n

2019-06-28 02:28发布

Presenting a UIDocumentMenuViewController to be able to load file into app. On iPhone it works, but not on iPad. Using iOS9. Any idea what is wrong?

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 Memorise[2994:977408] the behavior of the UICollectionViewFlowLayout is not defined because: 2016-06-07 09:45:45.260 Memorise[2994:977408] the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values. 2016-06-07 09:45:45.261 Memorise[2994:977408] The relevant UICollectionViewFlowLayout instance is <_UIAlertControllerCollectionViewFlowLayout: 0x1668e6e0>, and it is attached to ; animations = { bounds.origin=; bounds.size=; position=; }; layer = ; contentOffset: {0, 0}; contentSize: {0, 0}> collection view layout: <_UIAlertControllerCollectionViewFlowLayout: 0x1668e6e0>. 2016-06-07 09:45:45.262 Memorise[2994:977408] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

What I do not understand why error message refers collectionView? I do not use collectionView at all. Maybe UIDocumentMenuViewController has it as inner component?

2条回答
走好不送
2楼-- · 2019-06-28 03:09

I had the same problem. I set the sourceView = self.view, and had to make a sourceRect = theButton.frame.

查看更多
叼着烟拽天下
3楼-- · 2019-06-28 03:14

iPad has some special rules about ActionSheets and their cancel buttons, It usually depends on where you are displaying the ActionSheets from, so this is how you can resolve the crashing issue:

     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)
查看更多
登录 后发表回答