0

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



}
4

1 回答 1

1

您需要在数据数组中填充对象后调用重新加载数据,您需要将其放在响应闭包内部而不是外部,因为响应闭包在一段时间后被称为 Async 并且您的重新加载数据现在在您的视图中被立即调用确实加载了。当然,当您将其放入内部时,您需要将重新加载数据分派到主队列。

于 2016-04-12T04:27:00.410 回答