1

我通过将我的子类TableViewController化为PFQueryTableViewController. 我希望用户看到有人在提要上发布消息的确切时间,但我的代码PFTableViewCell编写不正确。基本上我想从 Parse 检索日期(或“createdAt”)。无论如何,我可以显示用户通过 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
        }

        }
4

1 回答 1

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
于 2015-10-31T17:49:28.340 回答