我有一个数组最佳数据源配置为UITableView的使用节
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
财产分组,和所有的itemName
小号按字母顺序排序。
到目前为止,我正在做我认为效率低下的事情。我正在对数组中的sectionName
属性执行Distinct
操作,然后使用它来命名节并对它们进行计数。之后,在CellForRowAtIndexPath
方法中,我只需使用sectionName
过滤数组,然后添加单元格。
我也想过使用NSFetchedResultsController
,但我不认为这会是一个好主意,因为数据本质上并不是持久的,因此不需要在managedObject
表单中。
在这种情况下,为分组表视图构造数据的理想方式是什么?
感谢Vadian的回应。 基本上,我无法控制数据,我以我从Web服务描述的形式接收数据。什么是最有效的方式,没有嵌套循环,将它们转换为所述结构? – NSFeaster