【问题标题】:Select creationDate from CloudKit record从 CloudKit 记录中选择 creationDate
【发布时间】:2016-01-28 22:15:14
【问题描述】:

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

我正在尝试以下操作,但我得到了一个无成员“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!
}

【问题讨论】:

  • objects 数组中有哪些类型的对象?也就是说object是什么类型的对象?
  • 你为什么要从创建日期获取“Notes”键?
  • var objects = [CKRecord]() 是我的对象。它是来自云套件的数组

标签: ios swift uitableview tableview cloudkit


【解决方案1】:

错误来自这一行:

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

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

只需将creationDate 作为NSDate 即可。然后使用NSDateFormatter 将日期格式化为可以分配给detailTextLabel.text 的字符串。

【讨论】:

    猜你喜欢
    • 2014-12-18
    • 2011-08-20
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-05
    • 1970-01-01
    • 2011-09-15
    相关资源
    最近更新 更多