一般我们填充cell数据使用
let cell = collectionView.mf_dequeueReusableCell(indexPath: indexPath) as MyConcernCell
cell.avatarImageView = UIImage(named:"")
cell.nameLabel.text = ""
return cell
如果cell属性过多会显得很乱,所以cell数据设置放到CellView中
首先在CellView中添加一个变量
import UIKit
import Kingfisher
class MyConcernCell: UICollectionViewCell,RegisterCellOrNib {
//认证
@IBOutlet weak var vipImageView: UIImageView!
//用户头像
@IBOutlet weak var avatarImageView: UIImageView!
@IBOutlet weak var nameLabel: UILabel!
//添加此属性用于接受Controller传来的数值
var myConcern:MyConcern?{
didSet{
avatarImageView.kf.setImage(with: URL(string: (myConcern?.icon)!))
nameLabel.text = myConcern?.name
if let isVerify = myConcern?.is_verify{
vipImageView.isHidden = !isVerify
}
}
}
}
设置好之后我们只需要在ViewController中添加此代码即可
cell.myConcern = myConcerns[indexPath.item]