Swift分析查询结果不会出现在tableview中

我遇到困难显示从我在tableview的单个单元格中查询的数据。 我相信我的逻辑是正确的,但是我没有看到我在包含Parse查询数据的函数中调用的console.log。 这可能是一个简单的解决方法,但目前还没有到我这里来。 控制台日志我应该看到,以validation我的查询正确通过是println("\(objects.count) users are listed") ,它应该然后显示在usernameLabel.text属性。

 import UIKit class SearchUsersRegistrationViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var userArray : NSMutableArray = [] @IBOutlet var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() tableView.delegate = self tableView.dataSource = self loadParseData() } func loadParseData() { var query : PFQuery = PFUser.query() query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]!, error:NSError!) -> Void in if error == nil { if let objects = objects { println("\(objects.count) users are listed") for object in objects { self.userArray.addObject(object) } self.tableView.reloadData() } } else { println("There is an error") } } } let textCellIdentifier = "Cell" func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.userArray.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier, forIndexPath: indexPath) as! SearchUsersRegistrationTableViewCell let row = indexPath.row let cellDataParse : PFObject = self.userArray.objectAtIndex(row) as! PFObject //cell.userImage.image = UIImage(named: usersArr[row]) cell.usernameLabel.text = cellDataParse.objectForKey("_User") as! String return cell } } 

我解决了这个问题。 我需要将用户数组中的索引path行作为PFUser ,然后将用户的用户名属性转换为string,然后将其设置为标签文本。

  let row = indexPath.row var user = userArray[row] as! PFUser var username = user.username as String cell.usernameLabel.text = username