【发布时间】:2015-12-24 10:14:08
【问题描述】:
出现错误:无法使用索引类型 Int 为值类型 [String:Double] 下标
override func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {//1
let cell = tableView.dequeueReusableCellWithIdentifier("cell",
forIndexPath: indexPath) //2
cell.textLabel?.text = menuItems.items[indexPath.section][indexPath.row]
return cell
}
我的MenuItems 如下所示:
class MenuItems:NSObject{
var sections:[String] = []
var items:[[String:Double]] = []
func addSection(section: String, item:[String:Double]){
sections = sections + [section]
items = items + [item]
}
}
class AnnMenuItems: MenuItems {
override init() {
super.init()
addSection("Threading", item: ["Eye Brows":100,"Upper Lip":100,"Forehead":100,"Chin":100,"Sides":100,"Face Waxing/Face Threading":100])
addSection("Hair", item: ["Rebonding":100,"Hair Dye":100,"Head Massage":100,"Streaking":100,"Hair Cut":100,"Straight Cut":100,"Children Cut":100,"Step Cut":100,"Layer Cut":100])
addSection("Waxing", item: ["Full Arms":100,"3/4 Arms":100,"Under Arms":100,"Full Legs":100, "3/4 Legs":100,"Half Legs":100])
addSection("Hair Treatments", item: ["Hair Spa":100,"Dandruff":100,"Hair Fall Treatment":100,"Galvanic Treatment":100, "Hair Wash":100,"Colour/Henna/Oil":100])
addSection("Facial", item: ["Clean Up Normal":100,"Black Heads":100,"Clean Up Special":100,"Herbal Facial":100, "Fruit Facial":100])
}
}
【问题讨论】:
-
我认为
menuItems.items是字典..你不能把字典索引 -
是的。那我该怎么做呢?
-
@iosmadness 有很多方法可以做到这一点,但所有这些都需要更改
menuItems类型。 -
text应该是什么?Threading或Eye Brows或100? -
Threading是标题项;Eye Brows的子部分,价格为100。我想把它放在一个静态表格单元格上。text应该是Eye Brows : 100