【发布时间】:2017-01-17 10:34:19
【问题描述】:
我花了很多时间 .. 但我不知道为什么它不工作 .. 调用索引路径的单元格并正确设置值,但单元格类我发现 nil 值 .. 如果您需要任何信息,请告诉我知道。
在我的 collectionview 索引路径中
在集合视图单元格中
这是我的代码:
对于收藏视图:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: menuBarItemDetailId, for: indexPath) as! MenuBarItemDetail
cell.shopCategory = "600"
print(cell.shopCategory)
return cell
}
对于单元格:
class MenuBarItemDetail: UICollectionViewCell , UITableViewDataSource , UITableViewDelegate {
var shopCategory : String?
override init(frame: CGRect) {
super.init(frame: frame)
print("shopCategory :-> ...i am calling from cell :\(shopCategory)")
}
【问题讨论】:
-
取可选值使用 print(cell.shopCategory)!
-
是的!我已经完成了,请检查第一张图片但没有结果..你是说那个吗
-
@Lalitkumar 是的可选值将其用作我的第一张图片
-
@cristanlika 在单元格类 UITableViewDataSource , UITableViewDelegate 中不需要这些,因为这是集合视图单元格,因此您需要将所有代表放入视图控制器并删除初始化函数。没必要。你可以使用 awakeFromNib