我正在尝试计算在PFQueryTableViewController
.
我试过解决
override func queryForTable() -> PFQuery {
let query = PFQuery(className: self.parseClassName!)
query.whereKey("member", equalTo: memberId!)
let count = query.countObjectsInBackground()
label.text = "\(count)"
return query
}
但是我的应用程序会崩溃。
编辑:
问题不是进行查询并计算它的对象。问题是使用queryForTable
将我的查询传递给cellForRowAtIndexPath
我的PFQueryTableViewController
cellForRowAtIndexPath
看起来像这样:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
let cell:DetailApplicantCell = self.table.dequeueReusableCellWithIdentifier("reuseIdentifier") as! DetailApplicantCell
if let name = object?.objectForKey(self.textKey!) as? String{
cell.nameLbl.text = name
}
cell.groupImage.image = UIImage(named: "People.png")
if let imageFile = object?.objectForKey(self.imageKey!) as? PFFile{
cell.groupImage.file = imageFile
cell.groupImage.loadInBackground()
}
return cell
}
请注意,这不是默认的 cellForRow