Select creationDate from CloudKit record

倾然丶 夕夏残阳落幕 提交于 2019-12-11 18:36:14

问题


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

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

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!
}

回答1:


The error is from this line:

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

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

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.



来源:https://stackoverflow.com/questions/35073175/select-creationdate-from-cloudkit-record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!