在我的cellForRowAtIndexPath中,我将Parse中的信息加载到每个单元格中。唯一的问题是每次刷新单元格时,Parse信息都会再次加载。我应该将代码移出cellForRowAtIndexPath并将其放在其他地方,还是应该将其包含在if语句中?如果需要更多信息或任何代码,请告诉我。谢谢!
这是我要刷新的代码......
func refresh() {
print("View appeared")
self.posts.removeAll(keepCapacity: false)
let postQuery = PFQuery(className: "Post")
postQuery.whereKey("type", equalTo: "world")
postQuery.orderByDescending("createdAt")
postQuery.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if let objects = objects as? [PFObject] {
self.posts = objects
self.table.reloadData()
}
})
}
答案 0 :(得分:1)
在viewDidLoad
中加载您的数据。然后在cellForRowAtIndex
中访问它。使用其他一些方法刷新数据,可能是下拉到新功能或新按钮事件。