来自plist数据的UITableView单元格字幕

时间:2013-12-04 14:54:35

标签: ios objective-c uitableview

我想在我的UITableView单元格中添加一些字幕(我在其中显示各大洲,国家和其他数据)。已经填满了我与大洲的第一张桌子。现在我想在每个大陆单元中添加多个国家作为副标题。我补充说:

int numberEurope;
numberEurope = [europe count]; //this works fine

int numberAfrica;
numberAfrica = [africa count]; //this works fine

NSNumber *myNum1 = [NSNumber numberWithInt:numberEurope];
NSNumber *myNum2 = [NSNumber numberWithInt:numberAfrica];

NSArray *myArray = [NSArray arrayWithObjects: myNum1, myNum2, nil];

cell.textLabel.text = ContinentName;
cell.detailTextLabel.text = [[NSString alloc] initWithFormat:@"%@ countries", myArray];
return cell;

但每个小区的字幕都相同,显示完整的数组:(2,2)个国家/地区,而不是第一个单元格中的2个国家/地区和第二个单元格中的2个国家/地区。我究竟做错了什么?我使用的plist是截图:Cannot Feed UITableView with .plist

1 个答案:

答案 0 :(得分:1)

您必须根据indexPath选择适当的值:

cell.detailTextLabel.text = [[NSString alloc] initWithFormat:@"%d countries", [[myArray objectAtIndex:[indexPath row]] intValue]];