【问题标题】:Unable to retrieve updatedAt or createdAt values from Parse objects无法从 Parse 对象中检索 updatedAt 或 createdAt 值
【发布时间】:2015-12-08 14:14:30
【问题描述】:

我是一位经验丰富的 Android 开发人员,正在尝试使用 Parse 服务和 sdk (https://www.parse.com/) 运行原型 iOS 应用程序。

太好了,我可以毫不费力地获得所有对象及其值,一切正常。

但是,我无法获取 Parse 为每个对象自动创建的 updatedAt 值。
这对我来说是必须的,当数据就在那里时,我不想将额外的时间戳保存为字符串。

这是我正在做的事情的要点。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}  

// this works fine 
cell.textLabel.text = [object objectForKey:@"name"];

//substring however does not
NSDate *updated = [object objectForKey:@"updatedAt"];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EEE, MMM d, h:mm a"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Lasted Updated: %@", [dateFormat stringFromDate:update]];

//i also tried like this at first
 cell.detailTextLabel.text = [NSString stringWithFormat:@"Lasted Updated: %@", [object objectForKey:@"updatedAt"]];

return cell;

}

【问题讨论】:

  • 如果你执行 NSLog(@"date %@",updated); 你会在调试器窗口中看到什么NSDate *updated = [object objectForKey:@"updatedAt"];
  • 你试过 [object stringForKey:@"updateAt"] 吗?

标签: ios objective-c parse-platform


【解决方案1】:

愚蠢的马特。我想了一天,然后在我发布它几分钟后意识到我的错误。

updatedAt 是所有 PFObjects 上的属性,无需使用键检索它。

给定一个名为对象的 PFObject...

 NSDate *updated = [object updatedAt];
 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
 [dateFormat setDateFormat:@"EEE, MMM d, h:mm a"];
 cell.detailTextLabel.text = [NSString stringWithFormat:@"Lasted Updated: %@", [dateFormat stringFromDate:updated]];

@Parse , 帽子的提示

【讨论】:

  • 谢谢哥们,我也遇到了同样的问题。
  • 大声笑,我挠头很长时间了。这是一个很大的帮助。非常感谢。已标记。
  • 这是很大很大的帮助。它让我卡了很长一段时间。
  • 我花了这么多时间在这上面!谢谢!
【解决方案2】:

对于 Swift:

let dateUpdated = object.updatedAt! as NSDate
let dateFormat = NSDateFormatter()
dateFormat.dateFormat = "EEE, MMM d, h:mm a"
cell.updatedAtLabel.text = NSString(format: "%@", dateFormat.stringFromDate(dateUpdated))

【讨论】:

    【解决方案3】:

    我刚遇到同样的问题,不要使用objectForKey访问,直接通过createdAt属性访问即可。

    在斯威夫特中

    object.createdAt

    如文档中所述,键:

    这不包括 createdAt、updatedAt、authData 或 objectId。它 确实包括用户名和 ACL 之类的内容。

    【讨论】:

      猜你喜欢
      • 2015-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-19
      • 1970-01-01
      • 2022-12-02
      • 1970-01-01
      相关资源
      最近更新 更多