我有一個數組最佳數據源配置爲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