2
我试图按照this 但是,当我做cell.checkmarkView.checked = true
它返回零,所以一切都崩溃。 这里是我的MyCollectionViewCell:UICollectionViewCell checkmark return nil
class MyCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var myLabel: UILabel!
var checkmarkView: SSCheckMark!
override init(frame: CGRect) {
super.init(frame: frame)
checkmarkView = SSCheckMark(frame: CGRect(x: frame.width-40, y: 10, width: 35, height: 35))
checkmarkView.backgroundColor = UIColor.white
contentView.addSubview(checkmarkView)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
//fatalError("init(coder:) has not been implemented")
}}
你能帮助我了解什么是错的?
我的CollectionView cellforitemat ...
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MyCollectionViewCell
cell.myLabel.text = self.listCivics()[indexPath.item]
cell.layer.borderWidth = 1
cell.checkmarkView.checked = true
return cell
}
“cell.checkmarkView.checked = true它返回nil”什么返回nil?你是否输入了'override init(frame:CGRect){'? – Larme
如果你是在谈论MyCollectionViewCell是的,我做你可以看到 – John
顺便说一句:最好是使用内容视图的“边界”而不是“框架”,你应该设置'autoresizingMask'。我会适当地更新我的答案。 – clemens