J'ai regardé partout pour cela, mais je suis incapable de trouver la réponse exacte ... tous ont de légères variations.NSArray imbriqué dans UITableView
Quoi qu'il en soit, j'appelle une page JSON qui renvoie les éléments suivants (du NSLog):
{
messages = {
1 = {
Body = "This is the body of message 1";
Title = "Message 1";
};
2 = {
Body = "This is the body of message 2";
Title = "Message 2";
};
};
}
Je puis enregistrer les données dans un NSDictionary (appelé messageArray). (Le tableau est un NSMutableArray)
alors je fais:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
//put rowsarray into dictionary
NSDictionary *dictionary = [messageArray objectAtIndex:indexPath.section];
//new dictionary into array
NSArray *messages = [dictionary objectForKey:@"messages"];
NSLog(@"the message array = %@",messages);
//this fails
cell.textLabel.text = [messages objectAtIndex:indexPath.row];
return cell;
le NSLog (donc je suppose mon tableau JSON fonctionne correctement) retourné:
the message array = {
1 = {
Body = "This is the body of message 1";
Title = "Message 1";
};
2 = {
Body = "This is the body of message 2";
Title = "Message 2";
};
}
Je comprends que je n'étiquette pas le textlabels.text correctement, mais je ne sais pas comment faire pour boucler à travers le tableau "messages", pour afficher toutes les valeurs "Title" du tableau, pour afficher sur mon interface utilisateur Liste TableView. Je suis certain qu'il me manque quelque chose de si simple ... mais il m'a échappé jusqu'à présent. Tous les liens bienvenue ... je vais continuer à me chercher ....
i ont ajouté cette ligne: NSLog (@ "% @", [messages objectAtIndex: indexPath.row]) ;, et il n'y a pas d'amour. je reçois le sélecteur non reconnu envoyé à l'instance. – btwong
try logging [messages class] – MCannon