【发布时间】:2017-07-01 17:29:46
【问题描述】:
我有一个数组
secInfArr = []
let secInf1 = SecInfObj.init()
secInf1.selected = true
secInf1.itemName = "item1"
secInf1.sectionName = "section3"
secInfArr.append(secInf1)
let secInf2 = SecInfObj.init()
secInf2.selected = true
secInf2.itemName = "item1"
secInf2.sectionName = "section1"
secInfArr.append(sectionInfo2)
let secInf3 = SecInfObj.init()
secInf3.selected = true
secInf3.itemName = "item1"
secInf3.sectionName = "section1"
secInfArr.append(secInf3)
let secInf4 = SecInfObj.init()
secInf4.selected = false
secInf4.itemName = "item1"
secInf4.sectionName = "section2"
secInfArr.append(secInf4)
我想创建一个tableView,其中所有这些内容都按sectionName 属性分组,并且该部分中的所有itemNames 都按字母顺序排序。
到目前为止,我正在做我认为效率低下的事情。我正在对数组中的sectionName 属性执行Distinct 操作,然后使用它来命名部分并计算它们。之后,在CellForRowAtIndexPath 方法中,我只需使用sectionName 过滤数组,然后添加单元格。
我也想过使用NSFetchedResultsController,但我认为这不是一个好主意,因为数据本质上不是持久的,因此不需要采用managedObject 形式。
在这种情况下,为分组表视图构建数据的理想方式是什么?
【问题讨论】:
标签: ios swift uitableview cocoa-touch