The World’s Largest Online Community for Developers

'; ios - UIDocumentMenuViewController crashes on iPad but not on iPhone - LavOzs.Com

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: [""], 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?

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)

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