ios - 我可以从解析中检索信息,也可以打印该数组,但是当我尝试将这些数组元素放入 tableviewcell 时,什么也没有显示

标签 ios arrays swift parse-platform

我可以从解析中检索信息,也可以打印该数组,但是当我尝试将这些数组元素放入 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/

相关文章:

javascript - iPhone X 和缺口检测

javascript - 在 JavaScript (Node.js) 中读取数字?

c - 将数字放置在随机坐标的“开放”槽中

ios - 如何在我正在创建的框架中使用 firebase?

ios - 如何快速设置一个具有 Alamofire 调用值的类变量?

ios - 访问 token 中生成的 facebook id 是否对于每个 session 都是唯一的?

ios - Ionic 4 谷歌地图插件 "failed to load optimized model at path..."

ios - Swift - 两个具有相同公共(public)结构的框架

javascript - 将 null 值替换为数组中的字符串,该字符串是 JSON 输出 - V2.0

ios - UIImageView 将(segue)nil 传递给另一个 ViewController