【发布时间】:2017-08-03 09:25:01
【问题描述】:
我有这个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 是否为零。如果它是 nil 那么在PostCell 我想打印“ss”,否则我想将postImage 的图像设置为PostImage。
【问题讨论】:
标签: ios swift uicollectionviewcell