如果我从情节提要中启动,则带有UICollectionView的UIViewController可以正常工作。但是,当我尝试像这样启动它时:

let imagePicker = imagePickerControllerViewController()
imagePicker.modalPresentationStyle = .OverCurrentContext
presentViewController(imagePicker, animated: true, completion: nil)


它崩溃在线:

collectionView.dataSource = self


问题是,如何正确显示模态显示的UIViewController(具有UICollectionView)?

最佳答案

替换为:

let imagePicker = imagePickerControllerViewController()


带有:

let imagePicker = storyboard.instantiateViewControllerWithIdentifier("imagePicker") as! imagePickerControllerViewController

关于ios - 如何在Swift中显示带有UICollectionView的弹出式UIViewController?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42165383/

10-10 20:36