Я использую быстрый и синтаксический анализ. Я использовал «query.orderbyDescending», но каким-то образом он не работает отлично. Я хочу упорядочить общий счет людей, но порядок выглядит следующим образом (например, 9, 7, 32, 21, 15 ....). Кажется, что кодирование распознает первую цифру числа. Как я могу это исправить? Вот мои коды. Спасибо!быстрый запрос синтаксиса orderbyDescending не работает
class IndividualStatsTVC: UITableViewController {
var postsArray = [PFObject]()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "background2.png")!)
tableView.separatorColor = UIColor.orangeColor()
fetchData()
print(postsArray)
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return postsArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("IndiStats", forIndexPath: indexPath) as! IndividualStatsTVCell
cell.yourname?.text = postsArray[indexPath.row].objectForKey("Name") as? String
cell.label1?.text = postsArray[indexPath.row].objectForKey("WIN") as? String
cell.label2?.text = postsArray[indexPath.row].objectForKey("DRAW") as? String
cell.label3?.text = postsArray[indexPath.row].objectForKey("LOSE") as? String
cell.label4?.text = postsArray[indexPath.row].objectForKey("AceError") as? String
cell.label5?.text = postsArray[indexPath.row].objectForKey("TOTAL") as? String
return cell
}
//cell color
func colorForIndex(index: Int) -> UIColor {
let itemCount = postsArray.count - 1
let color = (CGFloat(index)/CGFloat(itemCount)) * 1.0
return UIColor(red: 1.0, green: color, blue: 0.0, alpha: 0.1)
}
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell,
forRowAtIndexPath indexPath: NSIndexPath) {
cell.backgroundColor = colorForIndex(indexPath.row)
}
func fetchData(){
//empty postsArray
postsArray = []
//bring data from parse
let query = PFQuery(className: "IndividualStats")
query.orderByDescending("TOTAL")
// postsArray.sortInPlace({($0["TOTAL"] as! Int) > ($1["TOTAL"] as! Int)})
query.findObjectsInBackgroundWithBlock { (objects: [PFObject]?, error) -> Void in
if error == nil && objects != nil{
for object in objects! {
self.postsArray.append(object)
print(self.postsArray)
self.tableView.reloadData()
}
}
}}