我已到处寻找这个,但我无法找到确切的答案......都有轻微的变化。嵌套到UITableView的NSArray
无论如何,我叫一个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,但我不知道如何去循环“消息”数组,显示数组中的所有“标题”值,以显示在我的用户界面上TableView列表。
我确定我错过了这么简单的事情......但它直到现在都没有了。任何链接欢迎...我将继续寻找自己....
我已经加入此行:的NSLog(@ “%@”,[消息objectAtIndex:indexPath.row]),和没有爱。我得到无法识别的选择器发送到实例。 – btwong 2010-12-14 03:14:33
尝试记录[消息类] – MCannon 2010-12-14 22:02:30