从CloudKit记录中选择creationDate

从CloudKit记录中选择creationDate

本文介绍了从CloudKit记录中选择creationDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用标题和副标题填充一个单元格。记录中带有字段的标题和带有CreationDate的详细信息。

I'm trying to fill a cell with title and subtitle. Title with the field and detail with the CreationDate from the record.

我正在尝试以下操作,但没有成员'ObjectForKey'

I am trying the following but I am getting a no member 'ObjectForKey'

var objects = CKRecord

var objects = CKRecord

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let reuseIdentifier = "Cell"
    var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as UITableViewCell?
    if (cell != nil) {
        cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
    }

    let object = objects[indexPath.row]
    cell!.textLabel!.text = object.objectForKey("Notes") as? String
    cell!.detailTextLabel?.text = object.creationDate.objectForKey("Notes") as? String
    return cell!
}


推荐答案

错误来自此行:

cell!.detailTextLabel?.text = object.creationDate.objectForKey("Notes") as? String

由于某种原因,您试图从记录的创建日期获取 Notes键(即是 NSDate

For some reason you are trying to get the "Notes" key from the record's creation date (which is an NSDate.

只需获取 creationDate 作为 NSDate 。然后使用 NSDateFormatter 将日期格式化为可分配给 detailTextLabel.text 。

Just get the creationDate as an NSDate. Then use an NSDateFormatter to format the date into a string you can assign to the detailTextLabel.text.

这篇关于从CloudKit记录中选择creationDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 22:31