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

标签 ios objective-c uitableview

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

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) countries 而不是第一个单元格中的 2 个国家和第二个单元格中的 2 个国家。我究竟做错了什么?我使用的 plist 是此处的屏幕截图:Cannot Feed UITableView with .plist

最佳答案

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

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

关于ios - 来自 plist 数据的 UITableView 单元格字幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20378537/

相关文章:

ios - 我如何使用 swift 2.3 项目支持 iOS 版本 10.3

ios - 容器 View 中的自定义 UITableViewController

ios - 为什么我不能在nsableview单元格中放置nsarray

iphone - iOS成长动画CGAffineTransformMakeScale移动

ios - 为什么我在 tableView 中看到动画前的静态文本

ios - 将变量从 UIViewController 传递到 SK Scene

ios - iOS 8.1.3 上未安装企业应用程序部署

ios - 类型 'UIViewController' 的值没有成员 'varView'

ios - 如何在 Xcode 中以编程方式获取夏令时设置?

objective-c - 在Interface Builder中制作的UISearchDisplayController的contentView在哪里设置