【发布时间】:2017-06-26 00:15:51
【问题描述】:
---- 已回答----
我目前正在尝试按标签上的单词对我的 tableview 进行排序。每行至少有 9 种颜色可供用户选择(用户可以选择任意数量)。关于如何组织表格,我有一个特定的顺序,但是根据用户首先选择的行,行的顺序可以是任何东西(问题)。
我在想的是我按照我希望单词在第二个屏幕中显示的顺序创建一个数组:“红色,蓝色,绿色,......”然后以某种方式将该数组连接到 tableview。因此,如果 tableview 遵循这个顺序(红色、蓝色、绿色......),并且用户确实选择了蓝色,那么表格将被排序为“红色、绿色、......”。这意味着无论用户拥有或没有什么颜色,tableview 都将遵循数组的顺序。我尝试在谷歌上搜索这个问题的解决方案好几天,但似乎无法弄清楚。有什么建议么?我已经粘贴了颜色如何加载的代码:
func loadColors() {
let colorQuery = PFQuery(className: "Colors")
colorQuery.whereKey("userID", equalTo: PFUser.current()?.objectId! ?? String()) //getting which user
colorQuery.limit = 10
colorQuery.findObjectsInBackground { (objects, error) in
if error == nil {
self.colorTypeArray.removeAll(keepingCapacity: false)
self.colorNameArray.removeAll(keepingCapacity: false)
self.colorObjectIDArray.removeAll(keepingCapacity: false)
for object in objects! {
self.colorTypeArray.append(object.value(forKey: "colorType") as! String) // add data to arrays
self.colorNameArray.append(object.value(forKey: "colorName") as! String) // add data to arrays
self.colorObjectIDArray.append(object.objectId!) //appends the objectid
}
self.tableView.reloadData()
} else {
print(error?.localizedDescription ?? String())
}
}
}
//places colors in rows
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! ColorsCell //connects to color cell
cell.colorType.text = colorTypeArray[indexPath.row] //goes through array and puts colors on cell label
return cell
}
【问题讨论】:
标签: swift uitableview sorting parse-platform xcode8