我正在尝试从后面的无限表中加载数据,但我无法正确加载表。它只是保持空白。我在多个地方试过它们会导致崩溃。它可以去的唯一地方是在最后一次错误调用之后。但表格保持空白。相关代码在我的fetchingUserDataAsync()函数中。
import UIKit
class UserTableViewController: UITableViewController {
var backendless = Backendless.sharedInstance()
let follow:Follow = Follow()
var usernames = [""]
var userids = [""]
var userEmails = [""]
var isFollowing = [false]
func fetchingUserDataAsync() {
self.userids.removeAll(keepCapacity: true)
self.usernames.removeAll(keepCapacity: true)
self.isFollowing.removeAll(keepCapacity: true)
print("\n============ Fetching user data using the ASYNC API ============")
let query = BackendlessDataQuery()
backendless.persistenceService.of(BackendlessUser.ofClass()).find(
query,
response: { ( name : BackendlessCollection!) -> () in
let currentPage = name.getCurrentPage()
for names in currentPage as! [BackendlessUser] {
//print("User name = \(names.name)")
if(names.name != self.backendless.userService.currentUser.name){
self.usernames.append(names.name)
self.backendless.persistenceService.of(BackendlessUser.ofClass()).find(
query,
response: { ( objectId : BackendlessCollection!) -> () in
let currentPage = objectId.getCurrentPage()
for objects in currentPage as! [BackendlessUser] {
//print("User id = \(objects.objectId)")
if(objects.objectId != self.backendless.userService.currentUser.objectId){
self.userids.append(objects.objectId)
let currentUser = self.backendless.userService.currentUser
let user = objects.objectId
let whereClauseOne = "follower = '\(currentUser.objectId)' "
let whereClauseTwo = "following= '\(user)'"
//print ("I am following'\(whereClauseTwo)'")
self.backendless.persistenceService.of(objects.ofClass()).find(
query,
response: { objects -> () in
if let objects = objects{
self.isFollowing.append(true)
} else{
self.isFollowing.append(false)
}
},
error: { ( fault : Fault!) -> () in
print("Server reported an error: \(fault)")
}
)
}
}
},
error: { ( fault : Fault!) -> () in
print("Server reported an error: \(fault)")
}
)
}
}
},
error: { ( fault : Fault!) -> () in
print("Server reported an error: \(fault)")
}
)
//////////////////////////////////////////////////////////////////////////////////
self.tableView.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
fetchingUserDataAsync()
}
答案 0 :(得分:1)
您需要在数据数组填充对象后调用重载数据,您需要将其放在响应闭包内而不是外部,因为响应闭包在稍后的某个时间被称为Async并且您现在立即调用重新加载数据在你的视图中确实加载。 当然,当你把它放在里面时,你需要将重载数据分派到主队列。