Je dois afficher l'adresse Web "href"
en tant que cell.textlabel.text
dans un UITableView
. Toute aide serait grandement appréciée.Afficher la cellule.textLabel.text de la réponse JSON
JSON:
"grandfathers": [{
"id": "60",
"sons": [{
"id": "30",
"grandsons": [{
"id": "10",
"links": {
"api": {
"news": {
"href": "http://api.website.com/v1/family/grandfathers/sons/grandsons/10/news"
},
},
@interface:
@property (strong, nonatomic) NSArray *grandfathers;
@property (strong, nonatomic) NSMutableArray *sons;
@property (strong, nonatomic) NSArray *grandsons;
Tableau:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"standardCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Grandfather *grandfatherLocal = [grandfathers objectAtIndex:0];
Son *sonLocal = [grandfatherLocal.sons objectAtIndex:0];
// Not sure what to do here to get to the "href" eventually
// This was my best guess...
Grandson *grandsonLocal = [sonLocal.grandsons objectAtIndex:indexPath.row];
cell.textLabel.text = [grandsonLocal.links.api.news.href valueForKey:@"href"];
};
Je ne sais pas comment obtenir aux données imbriquées à ce moment-là. (Pour votre information, je mis en place des modèles et je utilise RestKit, donc ce le contexte de ce que je fais ici.)
EDIT: Je reçois rien affiché dans le tableau, et l'erreur dans la sortie est juste: "Impossible de trouver un mapping objet pour KeyPath: ''"
EDIT: Petit-fils Interface par demande:
@interface Team : NSObject
@property (nonatomic, strong) NSNumber *id;
@property (nonatomic, strong) Links *links;
+ (RKObjectMapping *) mapping;
@end
EDIT: Alessandro a parfaitement répondu à ma question, voir ci-dessous. BTW, il est allé au-dessus et au-delà pour m'aider, je suis super greatful-
Merci!
Possiblement lié - 'cell' peut être nul selon votre configuration. Avez-vous enregistré le fichier classe/nib pour votre cellule? De la docs: _ "Si aucune cellule n'est disponible pour être réutilisée et que vous n'avez pas enregistré de fichier class ou nib, cette méthode renvoie nil." _ –
valueForKeyPath: @ "links.api.news.href"? – Marc
La cellule @AaronBrager n'est pas nulle, mais merci pour le heads up juste au cas où il était – Realinstomp