2016-09-20 70 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 {方法。

我们没有内置的方法来定义节的节数。

相关问题