【问题标题】:I'm trying to populate a tableview with a list of users, but the tableview will not load anything我正在尝试使用用户列表填充表格视图,但表格视图不会加载任何内容
【发布时间】:2015-06-01 00:48:08
【问题描述】:

由于某种原因,我不断返回一个空白的 tableview。它显示正在从 Parse 加载查询,只是没有显示任何结果。提前感谢您的帮助。

class userViewController: PFQueryTableViewController {


    override init(style: UITableViewStyle, className: String!) {
        super.init(style: style, className: className)

    }

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        self.pullToRefreshEnabled = true

    }
    override func queryForTable() -> PFQuery {
        var query: PFQuery = PFUser.query()!
        println(query)
        return query
    }


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject!) -> PFTableViewCell {

        var userCell = tableView.dequeueReusableCellWithIdentifier("Cell2") as! PFTableViewCell!

        if userCell == nil {
            userCell = PFTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell2")
        }

        if let lastName = object["lastName"] as? String {
            var firstName = object["firstName"] as? String
            userCell?.textLabel?.text = "\(lastName), \(firstName)"

        }
        if let adminStatus = object["adminStatus"] as? Bool {
            if adminStatus == true {
            userCell?.detailTextLabel?.text = "Administrative Privliges"
            }else{
            userCell?.detailTextLabel?.text = "Non Administrative Privliges"
            }
        }

        return userCell
    }

    override func viewWillAppear(animated: Bool)
    {
        self.navigationController?.navigationBarHidden = false
    }
}

【问题讨论】:

    标签: ios uitableview swift parse-platform


    【解决方案1】:

    好像你没有正确初始化类,你需要设置你要查询的类的名字

    // Initialise the PFQueryTable tableview
    override init!(style: UITableViewStyle, className: String!) {
        super.init(style: style, className: className)
    }
    
    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    
        // Configure the PFQueryTableView
        self.parseClassName = "yourClass"
    
        self.textKey = "yourObject"
        self.pullToRefreshEnabled = true
        self.paginationEnabled = false
    }
    

    希望这段代码对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多