Ios 无法为UITableView提供.plist

Ios 无法为UITableView提供.plist,ios,iphone,objective-c,uitableview,plist,Ios,Iphone,Objective C,Uitableview,Plist,我是一个初学者,有一个很简单的问题。我浏览了类似的话题,没找到解决办法就浪费了一天。 我有一个主视图和详细视图控制器。我创建了一个.plist,如下所示。 现在我想向UITableView提供这些数据。这里的问题是。我不能接受大陆的名字。每当我看到空白单元格或出现错误时。也许我该换件衣服 这是我的密码: MasterViewController.h: @interface MasterViewController : UITableViewController @property (nona

我是一个初学者,有一个很简单的问题。我浏览了类似的话题,没找到解决办法就浪费了一天。 我有一个主视图和详细视图控制器。我创建了一个.plist,如下所示。

现在我想向UITableView提供这些数据。这里的问题是。我不能接受大陆的名字。每当我看到空白单元格或出现错误时。也许我该换件衣服

这是我的密码: MasterViewController.h:

@interface MasterViewController : UITableViewController

@property (nonatomic, strong) NSDictionary *world;
@property (nonatomic, strong) NSDictionary *africa;
@property (nonatomic, strong) NSDictionary *europe;

@end
MasterViewController.m(我添加内容的位置):

我有一个问题:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];


NSString *ContinentName = [world objectForKey:indexPath.row]; //I do something wrong here
cell.textLabel.text = ContinentName;

return cell;
}
如何在表格视图中显示我的大陆?如何在再次点击后显示国家和其他信息

谢谢你的帮助

经过这些更改后,它现在可以工作了:

NSArray *namesOfContintents = [world allKeys];
NSString *ContinentName = [namesOfContintents objectAtIndex:indexPath.row];

cell.textLabel.text = ContinentName;
我还想给单元格添加一些字幕。我补充说:

int numberEurope;
numberEurope = [europe count];

int numberAfrica;
numberAfrica = [africa count];

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个国家。我做错了什么

NSString *ContinentName = [world objectForKey:indexPath.row];
objectForKey
需要密钥的名称,您在
int
中给出了该名称

试试这个:

NSDictionary *ContinentName = [world objectForKey:@"Europe"];
此外,此处返回的值是
NSDictionary
,而不是字符串

我建议您将大陆转换为平面阵列

NSMutableArray *flatArray = [[NSArray alloc] init]; 
for(id item in world){
    [flatArray addObject:item];
}
您可以通过
indexPath.row

如果你想知道大陆的名字,你可以打电话

NSArray *namesOfContintents = [world allKeys];

当我添加“NSArray*flatArray…”时,我收到一个错误:“NSArray”没有可见的@interface声明选择器“addObject:”你能写下整个“tableView CellForRowatineXpath”块吗?对不起,它必须是NSMutableArray。阵列部分是额外的。请关注我以前写的内容,您将NSDictionary分配给NSString。是的,我现在看到了,但仍然不知道如何克服这个问题:(也许我应该重新组织我的plist,使其更易于使用?是的!我知道了!我添加了:NSArray*nameofcontents=[world allkey];NSString*continents=[nameofcontents objectAtIndex:indexath.row];cell.textlab.text=ContinentName;它现在正在工作。如何获得国家数量作为字幕有什么帮助吗?(我编辑了我的主要主题以提供更多信息)
NSArray *namesOfContintents = [world allKeys];