我正在从解析导入数据,并尝试添加“拉动刷新”功能,因此,如果有人添加对象,它将添加到表格视图中,但是现在它复制了表格视图中已经存在的内容。显然,如果未添加任何内容并且我刷新,则任何内容都不应更改。
会有很多帮助
这是我的下面的代码
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()
关于ios - 快速拉动以重新加载表中的重复对象而不是更新,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33618973/