mjw*_*mjw 13 objective-c ios parse-platform
我是一位经验丰富的Android开发人员,试图使用Parse服务和sdk(https://www.parse.com/)运行原型iOS应用程序.
这很棒,我可以毫无困难地获得所有物品和价值,一切正常.
但是,我无法获得Parse为每个对象自动创建的updatedAt值.
对我来说这是必须的,当数据就在那里时,我不想将一个附加的时间戳保存为String.
这是我正在做的事情的要点.
- (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;
Run Code Online (Sandbox Code Playgroud)
}
mjw*_*mjw 51
傻马特.我想这一天,然后在我发布之后实现我的错误.
updatedAt是所有PFObjects上的属性,无需使用密钥检索它.
给定一个名为object的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]];
Run Code Online (Sandbox Code Playgroud)

@Parse,小费的帽子
Lon*_*Guy 15
对于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))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10859 次 |
| 最近记录: |