我已经拿到了这个
现在我想要做的是检查
UICollectionViewCell
。func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! PostCell
if let CurrentPost = posts[indexPath.row] as? Post {
if(CurrentPost.PostImage == nil) {
print(CurrentPost.PostText)
}
}
return cell
}
class PostCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
designCell()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
let postImage: UIImageView = {
let v = UIImageView()
v.translatesAutoresizingMaskIntoConstraints = false
v.contentMode = .scaleAspectFill
return v
}()
func designCell() {
addSubview(postImage)
if (postImage.image == nil) {
print("ss")
}
cellConstraints()
}
}
现在我想要做的是检查
posts[indexPath.row]
中的PostImage
是否为空。如果它是空的,那么在PostCell
中我想打印"ss",否则我想将postImage
的图像设置为PostImage
。
Initializer does not override a designated initializer from its superclass
。 - sakoaskoasogetImage
gets called after the class is called,so it automatically gives it a value of nil` - sakoaskoasoconvenience init(frame: CGRect,image:UIImage?) { self.init(frame: frame) backgroundColor = .white designCell() }
但是它给了我一个错误,说self.init(frame: frame)
应该是self.init(coder: frame)
,然后又出现了另一个错误,说编码器和框架是不同的东西。 - sakoaskoaso