【发布时间】:2015-11-11 18:22:31
【问题描述】:
在 Parse 中,我不小心删除了一个名为“likes”的列,该列计算用户对其博客文章获得的赞数。我再次使用相同的名称创建了该列,但是现在当我运行我的应用程序时它崩溃并且我收到此消息“在展开可选值时意外发现 nil”。它指向我的代码,它假设在我的 cellForRowAtIndexPath 中接收“喜欢”。我在下面粘贴了我的代码。有什么办法可以解决这个问题并阻止它崩溃?
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath?) -> PFTableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("BCell", forIndexPath: indexPath!) as! BlogCell
if let object : PFObject = self.blogPosts.objectAtIndex(indexPath!.row) as? PFObject {
cell.author.text = object["blogger"] as? String
cell.post.text = object["blogPost"] as? String
let dateUpdated = object.createdAt! as NSDate
let dateFormat = NSDateFormatter()
dateFormat.dateFormat = "h:mm a"
cell.timer.text = NSString(format: "%@", dateFormat.stringFromDate(dateUpdated)) as String
let like = object[("likes")] as! Int
cell.likeTracker.text = "\(like)"
}
return cell
}
【问题讨论】:
-
let like = object[("likes")] as! Int行?
标签: ios swift parse-platform pfquery