[英]I am using the Parse.com in Swift , but update of TableView does not work
Using the Parse is MBaaS in Swift is making a program that displays the character that you enter in the TextField to TableView,but Part to be updated by pulling the TableView does not go well . 在Swift中,MBaaS使用Parse是一种程序,该程序可以显示您在TextField中输入的字符到TableView,但是要通过拉TableView进行更新的部分效果不佳。
override func viewDidLoad() {
super.viewDidLoad()
self.loadData()
// DataSource
tableView.dataSource = self
// Delegate
tableView.delegate = self
self.pullrefresh()
}
func loadData() {
var query:PFQuery = PFQuery(className: "Comment")
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock{(objects: [AnyObject]!, error: NSError!) -> Void in
if (error != nil){
//error
}
for object in objects {
self.comments.addObject(object)
}
self.tableView.reloadData()
}
}
func pullrefresh(){
self.refreshControl = UIRefreshControl()
self.refreshControl.attributedTitle = NSAttributedString(string: "↓pull")
self.refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refreshControl)
}
func refresh(sender:AnyObject){
self.loadData()
self.refreshControl.endRefreshing()}
And I wrote this kind of program , but when it pulled to update , you will see the same content .How do should I do to the text that is displayed on another screen to update only those that have not been displayed without displaying ? 我写了这种程序,但是当它被拉来更新时,您将看到相同的内容。我该如何处理另一个屏幕上显示的文本,以仅更新那些未显示而不显示的文本?
Use Grand Central Dispatch. 使用大中央调度。 In
query.findObjectsInBackgroundWithBlock
, replace this: 在
query.findObjectsInBackgroundWithBlock
,替换为:
for object in objects {
self.comments.addObject(object)
}
self.tableView.reloadData()
with this: 有了这个:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
// Task
for object in objects {
self.comments.addObject(object)
}
dispatch_async(dispatch_get_main_queue()) {
// UI
self.tableView.reloadData()
}
}
Try updating it on the main thread: 尝试在主线程上更新它:
dispatch_async(dispatch_get_main_queue(),{
self.tableView.reloadData()
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.