Jes*_*e C 3 ios uicollectionview swift3
尝试初始化集合视图类并收到以下错误:
必须调用超类'UICollectionView'的指定初始值设定项
数据正在从另一个ViewController传递,我希望在用户搜索时从ViewController中抽出框架.
class searchLocationsCollectionViewManager: UICollectionView, UICollectionViewDataSource, UICollectionViewDelegate {
weak var collectionView: UICollectionView! {
didSet {
collectionView.dataSource = self
collectionView.delegate = self
}
}
// Data handler
var data: [[String:Any]]? {
didSet {
print(data!)
//collectionView.reloadData()
}
}
init(collectionView: UICollectionView, frame: CGRect) {
self.collectionView = collectionView
super.init()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
// This is the current method for returning the cell.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
return UICollectionViewCell()
}
Run Code Online (Sandbox Code Playgroud)
关于上述原因发生的任何想法?
你需要调用指定的初始化init(frame:collectionViewLayout:)
的UICollectionView
.
init(collectionView: UICollectionView, frame: CGRect) {
self.collectionView = collectionView
//Setup collectionView layout here and pass with init
let layout = UICollectionViewLayout()
super.init(frame: frame, collectionViewLayout: layout)
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2906 次 |
最近记录: |