【发布时间】:2017-12-05 12:46:27
【问题描述】:
我正在尝试解析 Json 并将其显示为表视图单元格内的集合视图项。所以层次结构是这样的:
MainTableVIew -> TableViewCell -> CollectionView -> CollectionViewCell
所以我有 json
"payments":[{
"type":"card",
"title":"Card"
}, {
"type":"sms",
"title":"SMS",
"max_amount":24
},{
"type":"account",
"title":"Account",
"disabled":true,
"max_amount":-1
}]
我解析了它。 我做的下一件事是在
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "NewPaymentCell") as! NewPaymentTableViewCell
cell.package?.title = payments[indexPath.row].title
return cell}
是哪个包
var package : PromoPayment? {
didSet {
collectionView.reloadData()
}
}
和 PromoPayment 我获取字典的类。
在 NewPaymentCollectionView 类中,我还像这样填充单元格:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "NewPaymentCollectionCell", for: indexPath) as! NewPaymentCollectionViewCell
cell.paymentIcon.image = UIImage(named: iconImage[indexPath.row])
cell.kidPayment?.title = (package?.title)!
return cell
}
kidPayment 在哪里
var kidPayment : PromoPayment? {
didSet{
namePaymentTypeLabel.text = kidPayment?.title
}
}
它在NewPaymentCollectionViewCell: UICollectionViewCell类中建模
当我调试它返回我零..
感谢您的帮助。
【问题讨论】:
标签: ios json swift uitableview