【发布时间】:2016-02-20 17:38:32
【问题描述】:
为了以编程方式创建表格视图,我有一个如下所示的菜单设置,它包含部分和单元格。
var menu = [
"section 1": [
"point a",
"point b",
"point c"
],
"section 2": [
"point a",
"point b",
"point c",
"point d",
"point e"
],
"section 3": [
"point a"
]
]
struct Sections {
var sectionName : String!
var sectionObjects : [String]!
}
var sections = [Sections]()
for (key, value) in menu {
print("\(key) -> \(value)")
sections.append(Sections(sectionName: key, sectionObjects: value))
}
所以我希望它完全按照这个顺序插入(第 1 节 -> 第 2 节 -> 第 3 节)。
但实际上是按其他顺序插入的(从打印开始):
section 2 -> ["point a", "point b", "point c", "point d", "point e"]
section 1 -> ["point a", "point b", "point c"]
section 3 -> ["point a"]
我绝对不知道为什么菜单数组中的顺序会改变。 任何人都可以想象为什么或有一些建议吗?
谢谢和问候!
【问题讨论】:
标签: arrays swift tableview sections