通过将我的TableViewController
继承到PFQueryTableViewController
,我创建了一个类似facebook和twitter的新闻Feed。我希望用户看到有人在Feed上发布消息的确切时间,但我PFTableViewCell
中的代码写得不正确。基本上我想要检索日期(或者#34; createdAt""来自Parse。无论如何,我可以通过Parse显示用户发布的时间吗?
以下是我的代码:
override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?, object: PFObject!) -> PFTableViewCell? {
let cell = tableView!.dequeueReusableCellWithIdentifier("BCell", forIndexPath: indexPath!) as! Post
if let userPost : PFObject = self.posts.objectAtIndex(indexPath!.row) as! PFObject {
cell.account.text = object["username"] as? String
cell.tweet.text = object["message"] as? String
cell.Time.text = "\((indexPath!.row + 1) * 3)m"
cell.tweet.numberOfLines = 0
let score = object[("count")] as! Int
cell.favoriteCount.text = "\(score)"
let replycnt = object["replies"] as! Int
cell.replyCount.text = "\(replycnt) replies"
if let profilePic = object["photo"] as? PFFile {
cell.userImage.image = UIImage(named: "profileImage")
//cell.userImage.file = profilePic
}
}
答案 0 :(得分:1)
我明白了!
以下是我的代码:
let dateUpdated = object.createdAt! as NSDate
let dateFormat = NSDateFormatter()
dateFormat.dateFormat = "MMM d, h:mm a"
cell.Time.text = NSString(format: "%@", dateFormat.stringFromDate(dateUpdated)) as String