我似乎无法弄清楚为什么我的手机区域中没有数据。 这是我的TableView。单元格字段在单元格类中链接。小区标识符是" cell"。
当我拥有它" print"我得到的PFObject:
["Scott"] ["Hoffman"]
["Scott", "Johnny"] ["Hoffman", "Apple"]
["Scott", "Johnny", "dsgfdsfg"] ["Hoffman", "Apple", "dsdsgf"]
class ParticipantTableViewController: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
}
}
答案 0 :(得分:0)
问题是您在0
方法中返回tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
,不会呈现任何单元格。
您应该返回要渲染的单元格数,在您的情况下是您firstname
数组中的字符串数。所以你的方法看起来像:
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return firstname.count
}