![](/img/trans.png)
[英]Use PFQueryTableViewController (from parse) with Swift
[英]Parse/Swift : PFQueryTableViewController createdAt object not working
我想添加代表發布時間的UIlable
,我嘗試了3種不同的方法,但UIlable
成功
PS:我正在使用PFQueryTableViewController
更新:
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM-dd-yyyy HH:mm"
var useDate = dateFormatter.stringFromDate
cell.dateLabel.text = useDate
上面的代碼后,我得到此錯誤> 無法將類型NSDate-> string分配為String類型? 錯誤是指向cell.dateLabel.text = useDate的錯誤
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject ? ) - > PFTableViewCell ?
{
let cell = tableView.dequeueReusableCellWithIdentifier("cellImg", forIndexPath: indexPath) as!MoreCell
//Trial 1
cell.dateLabel.text = object ? .objectForKey(createdAt)
//Trial 2
cell.dateLabel.text = object ? .objectForKey("createdAt") as ? String
//Trial 3
cell.dateLabel.text = object ? .createdAt
//Trial 4
cell.dateLabel.text = object?.updatedAt >> Error Can't assign value of type NSDate to type string?
}
錯誤消息很容易解釋。 在解析中, updatedAt
標記是一個Date對象,而您試圖將其分配給包含字符串的對象。 因此,在嘗試為文本標簽設置日期之前,需要將日期更改為字符串。
編輯:
您需要像這樣使用日期格式化程序:
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM-dd-yyyy HH:mm"
let useDate = dateFormatter.stringFromDate(object["updatedAt"] as! NSDate)
cell.dateLabel.text = useDate
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.