我是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"]]
这里是我的函数这对于有多行的单个部分工作正常问题是我不知道如何使用索引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 :(得分:0)
将应该在数组中的同一部分中的元素分组,如下所示
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"]
]
]
您可以使用
访问它们cell.lblCityName.text!=menuItems[indexPath.section][indexPath.row]["city"]!