コアデータ呼び出しhasImageからの変数に基づいて2番目のセルを登録したいとします。変数が存在するとき、コレクションビューにメディアセルを使用したいときは、通常のセルを使用する必要があります。変数に基づくインデックスパスの項目のUICollectionViewセル
は、もともと私はインデックスパスでセルのために、次を使用:
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は完全に正常に動作し、それはそれはあなたがcellprop
変数のセッターを記載しているが、それが呼ばれることはありません通常の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'されますか? – D4ttatraya