我从下面的代码中得到以下错误。我不知道如何纠正这个错误,也找不到有用的答案。
void函数中意外的非void返回值
private func collectionView( _ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath){
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "a11", for: indexPath)
return cell ;
}
func UICollectionViewCell() {
}
func collectionView( _ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath)
的函数定义不是定义返回值,而是返回UICollectionViewCell
。这就是问题的原因。此外,您可能也不想使cellForItemAt
成为私有方法。您应该将其更新为
func collectionView( _ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "a11", for: indexPath)
return cell ;
}
-
您需要添加函数返回值并删除私有关键字
func collectionView(_ collectionView:UICollectionView,cellForItemAt indexPath:indexPath(->UI集合视图单元格{let cell=集合视图.dequeueReusableCell(具有ReuseIdentifier:"a11",用于:indexPath(
return cell
}
-
删除此代码
函数UICollectionViewCell(({
}
-
检查单元格中是否存在"this ID";a11";已注册。(在情节提要或代码中,具体取决于您的实现(。
你能提供错误的文本吗?