appname.ViewsVC collectionView:cellForItemAtIndexPath:]: 无法识别的选择器发送到实例
appname.ViewsVC collectionView:cellForItemAtIndexPath:]: unrecognized selector sent to instance
我正在构建集合视图并收到以下错误。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[appname.ViewsVC collectionView:cellForItemAtIndexPath:]: unrecognized selector sent to instance
这是我自定义单元格的代码
// cell configuration
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ViewsCell", for: indexPath) as! ViewsCell
cell.fullnameLbl.text = self.viewsArray[(indexPath as NSIndexPath).row].capitalizeEachWord
// pic setup
avaArray[indexPath.row].getDataInBackground { (data:Data?, error:Error?) in
if error == nil {
cell.avaImg.image = UIImage(data: data!)
}
}
return cell
}
我在故事板中创建了集合视图和单元格,并为它们提供了正确的标识符。我还将 UIimageView 和标签连接到单元格 class。
任何想法可能是错误的。
我意识到我在视图控制器的顶部缺少 UICollectionViewDataSource 和 UICollectionViewDelegate
class ViewsVC: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
我正在构建集合视图并收到以下错误。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[appname.ViewsVC collectionView:cellForItemAtIndexPath:]: unrecognized selector sent to instance
这是我自定义单元格的代码
// cell configuration
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ViewsCell", for: indexPath) as! ViewsCell
cell.fullnameLbl.text = self.viewsArray[(indexPath as NSIndexPath).row].capitalizeEachWord
// pic setup
avaArray[indexPath.row].getDataInBackground { (data:Data?, error:Error?) in
if error == nil {
cell.avaImg.image = UIImage(data: data!)
}
}
return cell
}
我在故事板中创建了集合视图和单元格,并为它们提供了正确的标识符。我还将 UIimageView 和标签连接到单元格 class。
任何想法可能是错误的。
我意识到我在视图控制器的顶部缺少 UICollectionViewDataSource 和 UICollectionViewDelegate
class ViewsVC: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {