本文介绍了快速拉动以重新加载表中的重复对象,而不是更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从解析导入数据,并尝试添加拉动刷新"功能,因此,如果有人添加对象,它将添加到表格视图中,但是现在它复制了表格视图中已经存在的内容.显然,如果没有添加任何内容并且我刷新,则什么都应该更改.
I am importing data from parse and trying to add a "pull to refresh" function so if someone adds an object it will add to the tableview, however right now it duplicates whats already in the tableview. Obviously if nothing has been added and i refresh nothing should change.
将提供很多帮助
这是我的下面的代码
var refresher: UIRefreshControl!
func Refresh() {
let query = PFQuery(className: "Events")
query.orderByAscending("Date")
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if error == nil {
// query successful - display number of rows found
print("Successfully retrieved \(objects!.count) Events")
if let objects = objects {
for object in objects {
self.postedEvents.append(object.objectForKey("Name") as! String)
self.postedImages.append(object.objectForKey("Image") as! PFFile)
self.postedObjects.append(object)
self.tableView.reloadData()
self.refresher.endRefreshing()
}
print(self.postedObjects.count)
print(self.postedEvents)
}
} else {
// Log details of the failure
NSLog("Error: %@ %@", error!, error!.userInfo)
}
}
}
override func viewDidLoad() {
refresher = UIRefreshControl()
refresher.attributedTitle = NSAttributedString(string: "Pull to Refresh")
refresher.addTarget(self, action: "Refresh", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refresher)
Refresh()
}
推荐答案
尝试在Refresh()
的第一行:
self.postedEvents.removeAll()
self.postedImages.removeAll()
self.postedObjects.removeAll()
这篇关于快速拉动以重新加载表中的重复对象,而不是更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!