【发布时间】:2016-03-09 11:53:15
【问题描述】:
大家好,我是 Swift 新手,目前遇到以下问题。 当在表视图控制器上选择一行时,它会推送一个集合视图控制器,但我收到此错误:
UICollectionView must be initialized with a non-nil layout parameter.
在 tableview 控制器上选择行时出现错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'
请指教一下?
应用代理:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.makeKeyAndVisible()
window?.rootViewController = CustomTabBarController()
return true
}
选项卡控制器已在选择行时使用表视图控制器进行初始化,它应该按到Collection View Controller
collection view cell 已经注册到viewDidLoad:
collectionView?.registerClass(PostCell.self, forCellWithReuseIdentifier: CELLID)
【问题讨论】:
-
class PostCell: UICollectionViewCell { override init(frame: CGRect) { super.init(frame: frame) setup() } required init?(coder aDecoder: NSCoder) { fatalError("init(coder: ) 尚未实现") } func setupViews(){ backgroundColor = UIColor.greenColor() }
-
我正在尝试在没有情节提要的情况下使用它。因此不确定如何在应用委托上初始化 collectionview 控制器
-
显示你的 cellForItemAtIndexPath
-
让单元格 = collectionView.dequeueReusableCellWithReuseIdentifier(CELLID, forIndexPath: indexPath) 返回单元格
标签: ios swift controller collectionview