Я искал повсюду это, но я не могу найти точный ответ ... у всех есть небольшие различия.
В любом случае, я вызываю страницу json, которая возвращает следующее (из 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";
};
};
}
Затем я сохраняю данные в NSDictionary (называемый messageArray). (массив является NSMutableArray)
тогда я делаю:
// 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;
возвращенный NSLog (поэтому я предполагаю, что мой массив json работает правильно):
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";
};
}
Я понимаю, что не правильно маркирую textlabels.text, но я не уверен, как выполнить цикл по массиву "messages", чтобы отобразить все значения "Title" из массива, чтобы отобразить на моем UITableView список.
Я уверен, что мне не хватает чего-то такого простого ... но это ускользало от меня до сих пор. Любые ссылки приветствуются ... я буду продолжать искать себя ....