【发布时间】:2018-01-06 21:59:27
【问题描述】:
在 Xcode 中,我在 userCell - UICollectionViewCell 的子类中创建了一个 var "userImage"。
import UIKit
class userCell: UICollectionViewCell {
@IBOutlet weak var userImage: UIImageView!
}
现在我想在我的集合视图上实现 cellForItem(at: IndexPath) 方法,但它返回的单元格没有那个“userImage”变量。
代码如下:
self.collection.cellForItem(at: path).userImage.image = UIImage(named: "1.jpg")
给出错误“'UICollectionViewCell?'类型的值?没有成员'userImage'"
代码如下:
self.collection.cellForItem(at: path) as userCell.userImage.image = UIImage(named: "1.jpg")
给出错误“Var 'userImage' 不是 'userCell' 的成员类型”
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewcell