我可以从解析中检索信息,也可以打印该数组,但是当我尝试将这些数组元素放入 TableView 单元格时,什么也没有显示 array.count 也返回 4 我不知道为什么表格单元格是空的
import UIKit
import Parse
class friendsViewController: UITableViewController {
var user = PFUser.currentUser()
var friends = [String]()
var profileFile = [PFFile]()
var height : CGFloat = UIScreen.mainScreen().bounds.size.height
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
//friends
var query = PFQuery(className:"Requests")
//query.orderByDescending("requestBy")
query.whereKeyExists("requestTo")
query.whereKey("requestBy", equalTo: PFUser.currentUser()!.username!)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
// The find succeeded.
println("Friends recieved \(objects!.count) scores.")
// Do something with the found objects
if let objects = objects as? [PFObject] {
for object in objects {
println(object)
self.friends.append(object["requestTo"] as! String)
println(self.friends)
}
} else {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
}
println(self.friends.count)
}
}
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return friends.count
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return (height/7)
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let myCell1 = tableView.dequeueReusableCellWithIdentifier("friendCell") as! friendsTableViewCell
myCell1.friendLabel.text = friends[indexPath.row]
return myCell1
}
最佳答案
friends
在表格 View 加载后 流行。收到数据后,在主线程上调用 tableView.reloadData()
。
关于ios - 我可以从解析中检索信息,也可以打印该数组,但是当我尝试将这些数组元素放入 tableviewcell 时,什么也没有显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30856943/