【发布时间】:2018-07-01 21:41:34
【问题描述】:
请帮助我用字典中的数据填充表格视图单元格。例如,我有这样的单元格:
为了用数据填充它,我开始重写cellForRowAt 方法:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CurrencyCell", for: indexPath) as! CurrencyCell
for (key, value) in currencies! {
print("key is - \(key) and value is - \(value)")
}
// ?
// cell.currencyLabel.text =
// cell.askLabel.text =
// cell.bidLabel.text =
return cell
}
字典的打印输出在这里:
key is - EUR and value is - Rate(ask: Optional("30.8500"), bid: Optional("30.1000"))
key is - USD and value is - Rate(ask: Optional("26.3000"), bid: Optional("26.0500"))
key is - RUB and value is - Rate(ask: Optional("0.4150"), bid: Optional("0.3750"))
如何做到这一点?提前致谢!
【问题讨论】:
-
将您的数据放入一个数组中,按照您希望它在表格中的显示方式排序。
标签: ios swift uitableview