任务未选中时功能不一致

时间:2016-03-02 04:37:06

标签: ios swift cloudkit

My To Do应用程序具有显示基于登录用户完成任务的人员的功能。出于某种原因,我可以在完成(检查)时将文本显示在任务下方,但是当我取消选中时,我无法使其消失。但是,当我取消选中任务时,任务文本会改变文本颜色,就像它应该的那样。对于为什么一个有效而另一个无效,似乎没有意义。 CloudKit仪表板更新已完成的bool(从true更改为false,反之亦然),但不包括completedBy键。

func doneHit(cell:TaskCell) {
        if let ip = tableView.indexPathForCell(cell) {
            let task = tasks[ip.row]
            let query = CKQuery(recordType: "Tasks", predicate: NSPredicate(format: "TRUEPREDICATE", argumentArray: nil))
            publicData.performQuery(query, inZoneWithID: nil) { (results:[CKRecord]?, error:NSError?) -> Void in
                if let _ = results {
                    task["done"] = cell.checkBox.isChecked
                    print(cell.checkBox.isChecked)
                        task["completedBy"] = "Completed by: \(self.user)"
                        cell.label.textColor = UIColor.grayColor()
                    }
                    else {
                        task["completedBy"] = ""
                        cell.label.textColor = UIColor.blackColor()
                    }

                    self.publicData.saveRecord(task, completionHandler: { (record:CKRecord?, error:NSError?) -> Void in
                        if error != nil {
                            print("Error: \(error!.localizedDescription)")
                            return
                        }
                        else {
                            print("Saved to iCloud")
                        }

                    })


                    dispatch_async(dispatch_get_main_queue(), { () -> Void in
                        self.tableView.reloadData()
                    })

                }
            }
        }

Task is checked and displays user

Task is unchecked, text changes color but user info remains

1 个答案:

答案 0 :(得分:0)

dispatch_async(dispatch_get_main_queue(), { () -> Void in
                        self.tableView.reloadData()
                    })

// Remove this line from the code