【发布时间】:2017-09-14 12:41:03
【问题描述】:
我是 iOS 开发新手,只是在从单个字典中填充不同部分的数据时遇到问题。这是我的字典
var menuItems = [["city":"Lahore","cityimage":"2","country":"Pakistan"],["city":"istanbul","cityimage":"3","country":"Turkey"],["city":"Moscow","cityimage":"4","country":"Russia"],["city":"Riyadh","cityimage":"5","country":"KSA"]]
这是我的函数,它适用于具有多行的单个部分,问题是我不知道如何在其中使用 index path.section
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell=tableView.dequeueReusableCell(withIdentifier: "TableCell", for:indexPath) as! TableCellTry
cell.lblCityName.text!=menuItems[indexPath.row]["city"]!
cell.lblProvince.text!=menuItems[indexPath.row]["country"]!
cell.imgCity.image=UIImage(named:menuItems[indexPath.row]["cityimage"]!)
}
【问题讨论】:
-
哪些元素应该在 #0 部分,哪些在 #1 部分?
-
第 0 部分的前 2 个城市和第 1 部分的后 2 个城市
-
那么@Michael 的answer 是对的。
标签: ios swift uitableview dictionary