Ios 如何在Swift中显示带有UICollectionView的弹出式UIViewController?

Ios 如何在Swift中显示带有UICollectionView的弹出式UIViewController?,ios,objective-c,swift,Ios,Objective C,Swift,如果我从情节提要启动带有UICollectionView的UIViewController,它可以正常工作。但是,当我尝试这样启动它时: let imagePicker = imagePickerControllerViewController() imagePicker.modalPresentationStyle = .OverCurrentContext presentViewController(imagePicker, animated: true, completion: nil)

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

let imagePicker = imagePickerControllerViewController()
imagePicker.modalPresentationStyle = .OverCurrentContext
presentViewController(imagePicker, animated: true, completion: nil)
它在网上崩溃了:

collectionView.dataSource = self
问题是,如何正确显示UIViewController(具有UICollectionView)模式?

替换为:

let imagePicker = imagePickerControllerViewController()
与:


您可以发布错误消息吗?致命错误:在展开可选值时意外发现nil这意味着在初始化collectionView或数据源之前正在调用collectionView.dataSource=self。
let imagePicker = storyboard.instantiateViewControllerWithIdentifier("imagePicker") as! imagePickerControllerViewController