【问题标题】:Display NSDictionary string in UITableView在 UITableView 中显示 NSDictionary 字符串
【发布时间】:2014-03-15 13:33:23
【问题描述】:

我的问题很简单:如何访问“matchs”字典并将其显示在 UITableView 中。

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

   static NSString *CellIdentifier = @"Cell";

   UITableViewCell *cell = [self getCellContentView:CellIdentifier andIndexPath:indexPath];

   NSArray *myArray = [contentDictio objectForKey:@"matchs"];
   cell.textLabel.text = [[myArray objectAtIndex:indexPath.row]objectForKey:@"guest_team"];

   cell.backgroundColor = [UIColor clearColor];

   return cell;
}

崩溃日志:-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x114a009c0 2014-03-15 14:34:18.127 01Foot[6089:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x114a009c0'

谢谢:-)

【问题讨论】:

  • 在哪里初始化 contentDictio?请也分享该代码。
  • 是 -> paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; path = [basePath stringByAppendingPathComponent:@"data-score.plist"]; arr = [[NSArray arrayWithContentsOfFile:path] mutableCopy]; contentDictio = [dict objectAtIndex: [[NSUserDefaults standardUserDefaults] integerForKey:@"index"]];

标签: uitableview nsdictionary plist unrecognized-selector


【解决方案1】:

您的屏幕截图显示匹配 [sic] 是一个字典(item5)(注意尽管 item0 它是一个数组)所以这一行...

NSArray *myArray = [contentDictio objectForKey:@"matchs"];

应该是

NSDictonary *myDictionary = [contentDictio objectForKey:@"matchs"];

然后,您需要确定您正在该字典中查看的哪些项目以获取“guest_team”

您需要对您的 plist 进行排序,使其保持一致

【讨论】:

  • 是的,但现在我如何才能访问guest_team
  • item0 是如何定义的,它是一个数组并且您的代码可以工作。如果您创建了 plist,请使其保持一致,即所有匹配项都应为数组
  • 看帖子顶部的图片,items是字典,matchs是包含多个字典的字典
猜你喜欢
  • 1970-01-01
  • 2013-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多