【发布时间】:2021-04-09 05:16:07
【问题描述】:
我正在配置一个集合视图以使用我自己的自定义单元格但是,我一直想知道为什么我必须在 collectionview.register(any class, forCellReuseIdentifier) 内的单元格类中包含 .self。
也许我的 OOP 技能只是在这里缺乏,但为什么 .self 会引用类型对象呢?为什么需要知道类型?任何帮助将不胜感激。
func configureCollectionView() {
collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: UICollectionViewLayout())
view.addSubview(collectionView)
collectionView.backgroundColor = .systemPink
//collectionView.register(FollowerCell.self, forCellWithReuseIdentifier: FollowerCell.reuseID)
collectionView.register(FollowerCell, forCellWithReuseIdentifier: FollowerCell.reuseID)
}
class FollowerCell: UICollectionViewCell {
static let reuseID = "FollowerCell"
let avatarImageView = GFAvatarImageView(frame: .zero)
let userNameLabel = GFTitleLabel(textAlignment: .center, fontSize: 16)
override init(frame: CGRect) {
super.init(frame: frame)
configure()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewcell