gpt4 book ai didi

ios - TableView 重新加载未从 Backendless 正确更新

转载 作者:行者123 更新时间:2023-11-29 01:04:33 24 4
gpt4 key购买 nike

我正在尝试从后面的无尽表中加载数据,但我无法正确加载该表。它只是保持空白。我在多个地方尝试过,它们会导致崩溃。它唯一可以去的地方是在最后一个错误调用之后。然而,该表保持空白。相关代码在我的 fetchingUserDataAsync() 函数中。

这是我的 TableView Controller :

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()



}

最佳答案

您需要在数据数组中填充对象后调用重新加载数据,您需要将其放在响应闭包内而不是外部,因为响应闭包会在一段时间后调用 Async 并且现在会立即调用您的重新加载数据在您看来确实加载了。当然,当你把它放进去时,你需要将重新加载的数据分派(dispatch)到主队列。

关于ios - TableView 重新加载未从 Backendless 正确更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36560721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com