0
帶有UICollectionView的UIViewController工作正常,如果我從故事板中啓動它。然而,當我嘗試推出這樣的:如何在Swift中顯示帶有UICollectionView的UIViewController?
let imagePicker = imagePickerControllerViewController()
imagePicker.modalPresentationStyle = .OverCurrentContext
presentViewController(imagePicker, animated: true, completion: nil)
它崩潰上線:
collectionView.dataSource = self
的問題是,如何展現一個UIViewController(具有UICollectionView)模態正常嗎?
你能後的錯誤訊息? –
致命錯誤:在解包可選值時意外發現爲零 –
這意味着在初始化collectionView或數據源之前調用collectionView.dataSource = self。 –