Swift: TableView,循环文本数组
Swift: TableView, looping an array of text
我能够将数组串入 UITableView。程序执行时。以下显示:
Chp1
Chp2
chp3
这个 for 循环是我在 atm 上工作的..
for i in 1 ..< Chapters.count {
FirstTableArray += [(Chapters[i])]
}
for i in 1 ..< Sections.count {
SecondTableArray += [SecondTable(SecondTitle:[Sections[i]])]
}
它执行以下导航..
Chp1 > Sec1
Chp2 > Sec2
Chp3 > Sec3
我怎样才能让它执行以下操作?
Chp1 > Sec1
> Sec2
> Sec3
这是我要进行的整个片段:
if var path = NSBundle.mainBundle().pathForResource("Chapters", ofType: "txt"){
var data = String(contentsOfFile:path, encoding: NSUTF8StringEncoding, error: nil)
if var content = (data){
var line: [String] = content.componentsSeparatedByString("\n")
let Chapters: [String] = content.componentsSeparatedByString("#")
let Sections: [String] = content.componentsSeparatedByString("1.")
let Headings: [String] = content.componentsSeparatedByString("/H")
for i in 1 ..< Chapters.count {
FirstTableArray += [(Chapters[i])]
}
for i in 1 ..< Sections.count {
SecondTableArray += [SecondTable(SecondTitle:[Sections[i]])]
}....
使用 NSDictionary,将章节名称存储为 "Key",将章节数组存储为 "Value"
你会得到类似的东西:
NSDictionary *book;
...
chapters = book.allKeys; // array of chapters
sectionsForChapters = book[chapters[0]]; // array of sections for the first chapter
我能够将数组串入 UITableView。程序执行时。以下显示:
Chp1
Chp2
chp3
这个 for 循环是我在 atm 上工作的..
for i in 1 ..< Chapters.count {
FirstTableArray += [(Chapters[i])]
}
for i in 1 ..< Sections.count {
SecondTableArray += [SecondTable(SecondTitle:[Sections[i]])]
}
它执行以下导航..
Chp1 > Sec1
Chp2 > Sec2
Chp3 > Sec3
我怎样才能让它执行以下操作?
Chp1 > Sec1
> Sec2
> Sec3
这是我要进行的整个片段:
if var path = NSBundle.mainBundle().pathForResource("Chapters", ofType: "txt"){
var data = String(contentsOfFile:path, encoding: NSUTF8StringEncoding, error: nil)
if var content = (data){
var line: [String] = content.componentsSeparatedByString("\n")
let Chapters: [String] = content.componentsSeparatedByString("#")
let Sections: [String] = content.componentsSeparatedByString("1.")
let Headings: [String] = content.componentsSeparatedByString("/H")
for i in 1 ..< Chapters.count {
FirstTableArray += [(Chapters[i])]
}
for i in 1 ..< Sections.count {
SecondTableArray += [SecondTable(SecondTitle:[Sections[i]])]
}....
使用 NSDictionary,将章节名称存储为 "Key",将章节数组存储为 "Value" 你会得到类似的东西:
NSDictionary *book;
...
chapters = book.allKeys; // array of chapters
sectionsForChapters = book[chapters[0]]; // array of sections for the first chapter