2016-09-20 69 views
1

標題說明了這一切。我想顯示一個數組的數組和數組2具有行的多個陣列,每個陣列指數是否有可能在UItableView中有多個部分:例如:部分1有兩個部分,這兩個部分有多個部分

這是它會是什麼樣子,如果你喜歡的視覺的東西

Section 1: 
    Section 1 
     Section 1 
      Cell 
     Section 2 
      Cell 
    Section 2 
     Section 1 
      Cell 
     Section 2 
      Cell 
Section 2 
    Section 1 
     Section 1 
      Cell 
     Section 2 
      Cell 
    Section 2 
     Section 1 
      Cell 
     Section 2 
      Cell 
Section 3 
    Section 1 
     Section 1 
      Cell 
     Section 2 
      Cell 
    Section 2 
     Section 1 
      Cell 
     Section 2 
      Cell 
+0

IDTS可能。 –

回答

1

的UITableView已支持沒有內置此但你可以用一些自定義標題和單元格自己創建一些東西。

基本上建立了一個模型來支持結構:

let model = [[[a, b],[c,d]],[[e,f],[g,h]]] 

numberOfSections實現將返回model.map{$0.count}.reduce(0, +)

numberOfRowInSection會做類似

let subSections = model[section] 
var topLevelRow = indexPath.row 
for subSection in subSections { 
    if topLevelRow < subSection.count { 
     print(subSection[topLevelRow]) 
     break 
    } else { 
     topLevelRow -= subSection.count 
    } 
} 

相同的實現,可用於createCellAtIndexPath

最後一部分是在部分是頂部部分(subSection [0])時提供一個標題,如果不是則提供另一個標題。

還有多層次的tableview在這篇文章中如何去做一個很好的例子: http://sapandiwakar.in/nested-sections-in-uitableview/

1

我不這麼認爲其容易實現,因爲我們定義分組表的數量可以用func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {方法。

我們沒有內置的方法來定義節的節數。

相關問題