本文介绍了无法从 Parse 对象中检索 updatedAt 或 createdAt 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名经验丰富的 Android 开发人员,正在尝试使用 Parse 服务和 sdk (https://www.parse.com/).

I'm an experienced Android developer trying to get a prototype iOS app running using the Parse service and sdk (https://www.parse.com/).

太棒了,我可以轻松获取所有对象及其值,一切正常.

It's great, and i can get all my objects and their values with no trouble, everything works fine.

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

However, i cannot get the updatedAt value automatically created by Parse for each object.
It's a must for me, and I dont want to have to save an aditional timestamp as a String when the data is sitting right there.

这就是我正在做的事情的要点.

This is the gist of what i was doing.

- (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;

}

推荐答案

Silly Matt.我想了一天,然后在我发布后几分钟意识到我的错误.

Silly Matt. I think about this for a day then realise my mistake minutes after i post it.

updatedAt 是所有 PFObjects 的一个属性,不需要使用键来检索它.

updatedAt is a property on all PFObjects, no need to retrieve it using a key.

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

Given a PFObject named object...

 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 , 提示

这篇关于无法从 Parse 对象中检索 updatedAt 或 createdAt 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:04