我要做的是显示的日期和时间与您在Facebook中看到的有些相似。但是,Xcode显示此错误:
使用未解析的标识符'creator'。
这是我的功能,我遇到了麻烦:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("PostCell", forIndexPath: indexPath) as! PostCell
cell.post = posts[indexPath.row]
cell.index = indexPath.row
var dataFormatter:NSDateFormatter = NSDateFormatter()
dataFormatter.dateFormat = "yyyy-MM-dd HH:mm"
cell.timestampLabel.text = dataFormatter.stringFromDate(creator.createdAt)
return cell
}
直到我输入第二行到最后一行代码才显示错误。具体来说,我知道错误是由creator
造成的,但我也认为timestampLabel
也是罪魁祸首,因为它没有像我在视频中跟随的那样改变颜色。现在我正在利用Parse存储所有用户数据,creator
是我在Parse中的类别之一。我希望有人可以指出我正确的方向,因为我已经花了很长时间来处理可能非常简单的事情。
答案 0 :(得分:3)
罪魁祸首不是时间戳标签。罪魁祸首是创造者对象。
使用未解析的标识符'创建者'
表示该对象未在当前范围中定义。在你的情况下创建者对象。应该定义创建者。
假设从youtube视频和你的代码posts
对象是一个解析对象数组(PFObject)
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("PostCell", forIndexPath: indexPath) as! PostCell
cell.post = posts[indexPath.row]
cell.index = indexPath.row
//---------------------------Add this-------------------
var creator = cell.post as PFObject
//------------------------------------------------------
var dataFormatter:NSDateFormatter = NSDateFormatter()
dataFormatter.dateFormat = "yyyy-MM-dd HH:mm"
cell.timestampLabel.text = dataFormatter.stringFromDate(creator.createdAt)
return cell
}