2013-08-25 13 views
11

Sono uno sviluppatore Android esperto che cerca di ottenere un prototipo di app iOS in esecuzione utilizzando il servizio Parse e sdk (https://www.parse.com/).Impossibile recuperare valori aggiornatiAt o creatiAt dagli oggetti Parse

È fantastico, e posso ottenere senza problemi tutti i miei oggetti e i loro valori, tutto funziona perfettamente.

Tuttavia, non riesco a ottenere il valore UpdateAt creato automaticamente da Parse per ciascun oggetto.
È un must per me e non voglio dover salvare un timestamp adizionale come una stringa quando i dati sono seduti proprio lì.

Questo è l'essenza di ciò che stavo facendo.

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

}

+0

Cosa si vede nella finestra del debugger se si esegue NSLog (@ "data% @", aggiornata); dopo NSDate * updated = [oggetto objectForKey: @ "updatedAt"]; – Yan

+0

hai provato [object stringForKey: @ "updateAt"]? –

risposta

50

Sciocco Matt. Penso a questo per un giorno, poi realizzo il mio errore pochi minuti dopo averlo pubblicato.

updatedAt è una proprietà su tutti i PFObjects, non è necessario recuperarlo utilizzando una chiave.

Dato un oggetto PFObject di nome ...

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

Working Date String

@Parse, punta del cappello

+0

Grazie amico, ho avuto lo stesso problema. – Ricardo

+0

Lol, mi stavo grattando la testa da molto tempo. Questo è stato di grande aiuto. Molte grazie. Segnato. – LondonGuy

+0

Questo è stato di grande aiuto. Mi ha bloccato per un bel po '. –

15

per 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)) 
2

Ho appena avuto lo stesso problema, non accedervi usando objectForKey, basta accederci direttamente tramite la proprietà createdAt.

a Swift

object.createdAt

Come indicato nei documenti, le chiavi:

Questo non includono createdAt, updatedAt, AuthData o objectId. Lo include cose come username e ACL.

Problemi correlati