0
我得拉刷新时重新加载表中存在的表重新载入数据前一秒钟的延迟,除了伟大的工作。拉刷新:刷新数据延迟
难道我只是有一些小东西出来的地方?有任何想法吗?
viewDidLoad
:
override func viewDidLoad() {
super.viewDidLoad()
self.refreshControl?.addTarget(self, action: "handleRefresh:", forControlEvents: UIControlEvents.ValueChanged)
self.getCloudKit()
}
handleRefresh
为拉刷新:
func handleRefresh(refreshControl: UIRefreshControl) {
self.objects.removeAll()
self.getCloudKit()
dispatch_async(dispatch_get_main_queue(), {() -> Void in
refreshControl.endRefreshing()
})
}
需要在两个地方的数据,所以创建了一个功能它getCloudKit
:
func getCloudKit() {
publicData.performQuery(query, inZoneWithID: nil) { results, error in
if error == nil { // There is no error
for play in results! {
let newPlay = Play()
newPlay.color = play["Color"] as! String
self.objects.append(newPlay)
}
dispatch_async(dispatch_get_main_queue(), {() -> Void in
self.tableView.reloadData()
})
} else {
print(error)
}
}
}
tableView
:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)
let object = objects[indexPath.row]
if let label = cell.textLabel{
label.text = object.matchup
}
return cell
}
在调用模块 – Paulw11
@ Paulw11之前,您不应该调用'endRefreshing'感谢您的回应!我认为现在有道理。不过,我会怎么做,在代码中,我有,因为我不想把'endRefreshing'我'getCloudKit'功能权限(因为我只需要使用'endRefreshing'为拉来刷新不'viewDidLoad'吧? )? – SRMR
无论如何你都可以调用endRefreshing。如果控制器不处于refreshingg状态,它将忽略它 – Paulw11