我有许多部分,其中包含来自解析数据库的以下数据结构。我不知道如何将它设置为数组并在swift的各个tableview部分中正确显示。
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String {
var name:String = "XXX"
var query = PFQuery(className: "category")
query.whereKey("type", equalTo:"\(Item)")
query.whereKey("section", equalTo:i)
query.getFirstObjectInBackgroundWithBlock {
(object: PFObject!, error: NSError!) -> Void in
if error == nil {
println("Successfully retrieved ")
let name = object["title"] as String
} else {
NSLog("Error: %@ %@", error, error.userInfo!)
}
}
return name
}
答案 0 :(得分:0)
您的数据结构应该是自定义对象的数组(取决于您的值):
class yourClass
{
var sectionTitle = ""
var subData:[String] = [] //Here you can define array of AnyObject
}
var yourData:[yourClass] = []
从Parse获取数据后,您只需遍历解析后的数据并将其添加到数据结构中:
var tmp = yourClass()
tmp.sectionTitle = "someSection"
tmp.subData = ["First subtitle","Second subtitle", "Thirt subtitle"]
yourData.append(tmp)
然后您将数据排序如下:
yourData[0].sectionTitle //This is your first section title
yourData[1].sectionTitle //This is your second section title
yourData[0].subData[0] //This is your first subtitle in your first section
等等......