【发布时间】:2017-05-15 12:50:11
【问题描述】:
我想根据核心数据调用 hasImage 中的变量注册第二个单元格。当变量存在时,我希望集合视图使用媒体单元格,当它不存在时,我希望它使用常规单元格。
最初我在索引路径的单元格中使用了以下内容:
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath :
IndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as!
ShareCell
let friend = fetchedResultsController.object(at: indexPath) as! Friend
cell.cell = friend.lastMessage
return cell
}
上面的代码运行良好。
以下是我创建新逻辑的尝试。
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath :
IndexPath) -> UICollectionViewCell{
var cellprop: Cell? {
didSet{
if cellprop?.hasImage == false {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as!
ShareCell
let friend = fetchedResultsController.object(at: indexPath) as! Friend
cell.cell = friend.lastMessage
return cell
}
}
}
}
我得到的错误是 void 函数中的意外非 void 返回值。
有什么建议吗?
编辑:
ShareCell 工作得非常好,它被归类为 BaseCell,除了它是一个普通的 collectionViewCell 之外,它还被定义为
class BaseCell: UICollectionViewCell {
override init(frame: CGRect){
super.init(frame: frame)
setupViews()
}
required init?(coder aDecoder: NSCoder){
fatalError("init(coder:)has not been implemented")
}
func setupViews(){
backgroundColor = UIColor.white
}
}
【问题讨论】:
-
cell.cell是什么意思?
标签: ios swift xcode uicollectionview