Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Uitableview TableView不显示数据_Uitableview_Parse Platform_Swift2 - Fatal编程技术网

Uitableview TableView不显示数据

Uitableview TableView不显示数据,uitableview,parse-platform,swift2,Uitableview,Parse Platform,Swift2,我似乎不明白为什么我的单元格字段中没有数据。 这是我的桌面视图。单元字段在单元类中链接。单元标识符为“单元” 当我让它“打印”我得到的对象时: ["Scott"] ["Hoffman"] ["Scott", "Johnny"] ["Hoffman", "Apple"] ["Scott", "Johnny", "dsgfdsfg"] ["Hoffman", "Apple", "dsdsgf"] 类参与者TableViewController:UITableViewController{ let

我似乎不明白为什么我的单元格字段中没有数据。 这是我的桌面视图。单元字段在单元类中链接。单元标识符为“单元”

当我让它“打印”我得到的对象时:

["Scott"] ["Hoffman"]
["Scott", "Johnny"] ["Hoffman", "Apple"]
["Scott", "Johnny", "dsgfdsfg"] ["Hoffman", "Apple", "dsdsgf"]
类参与者TableViewController:UITableViewController{

let userLabel = PFUser.currentUser()?.username
var firstname = [String]()
var lastname = [String]()
var laps = [String]()

override func viewDidAppear(animated: Bool) {
}
override func viewDidLoad() {
    super.viewDidLoad()

   // self.navigationItem.title = userLabel

   self.navigationItem.setHidesBackButton(false, animated:true);

    // Query database for school
    let currentUser = PFUser.currentUser()
    let userSchool = currentUser!.objectForKey("school") as! String
    print(userSchool)

    //Query database for Participants
   let query = PFQuery(className:"Participant")
   query.whereKey("school", equalTo:userSchool)
    query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in

        if let objects = objects {
            for object:PFObject in objects {
                self.firstname.append(object["firstname"] as! String)
                self.lastname.append(object["lastname"] as! String)

             //   self.laps.append(object["laps"] as! String)

             print(self.firstname, self.lastname)
                self.tableView.reloadData()
            }
        }
    })
    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
   // self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
   super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return 0
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell:ParticipantTableViewCell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! ParticipantTableViewCell
    // Configure the Cell


    cell.firstnameLabel.text = self.firstname[indexPath.row] as String;
    cell.lastnameLabel.text = self.lastname[indexPath.row] as String;
  //myCell.lapLabel.text = self.laps[indexPath.row]


    return cell
}

}

问题是您在
表视图(tableView:UITableView,numberOfRowsInSection:Int)->Int
方法中返回
0
,将不会呈现任何单元格

您应该返回要渲染的单元格数,在您的情况下,它是
firstname
数组中的字符串数。因此,您的方法如下所示:

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return firstname.count
}

如果在
tableView(tableView:UITableView,numberofrowsinssection:Int)->Int
方法中返回
0
,当我将[tableView(tableView:UITableView,numberofrowsinssection:Int)->Int]更改为1时,任何单元格都将被渲染,我得到一个错误:致命错误:数组索引超出范围,对于此行:cell.firstnamelab.text=self.firstname[indexPath.row]作为字符串;这是因为您在加载名称之前渲染单元格,您应该在numberOfRows方法中返回数组中对象的计数(例如,
self.firstname.count
)啊,现在知道了,谢谢我将其作为答案发布,因为我喜欢点数