0
我真的很困惑尝试init()我的自定义单元类中的一些东西,我想成为一个collectionview的数据源和委托。init()是自定义单元类中的委托和数据源的collectionView
我如何初始化(),以便我有数据中的数据准备被cellForItemAt使用?
var partArray : [CollectionStruct] = []
init(partArray: [CollectionStruct]) {
super.init(partArray: [CollectionStruct])
innerCollectionView.delegate = self
innerCollectionView.dataSource = self
//innerCollectionView.tag = item
// add some stuff from local sql lite to array
// this is how i normally do this in viewDidLoad
// but cant use that in cell subclass
BuildArray.buildArrayFromQuery(queryForCollection: "Part", delegateSender: "DownloadPack", completeBlock: { (result) in
if result.isEmpty == false {
self.partArray = result
}
})
}
如果我只是做:
init() {
// stuff for the array
}
我得到迅速提示我有此块:
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
您无法创建自定义初始程序。您需要实施所需的初始程序并提供一些其他功能来加载数据。 – Paulw11
只是在重新加载您的单元格对象collectionview之前分配数据。 – iAviator
我不明白这是什么意思..在这种情况下从哪里重新加载数据?如果单元格是嵌套collectionView的数据源,那么需要在这里分配数据? – Pippo