我在iPhone中的表观视图有问题。.我无法弄清楚为什么每次都会崩溃是代码

   - (void)viewDidLoad
{
     [self checkAndCreatePList];
    NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:pListPath];

    self.animals = [plistDict objectForKey:@"Animals"];



         [super viewDidLoad];

}



    -(UITableViewCell *) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath
{
    static NSString *SimpleTableIdentifier =@"SimpleTableIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
    if(cell== nil){
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SimpleTableIdentifier]autorelease];
    }
    NSUInteger row = [indexPath row];

    cell.textLabel.text = [animals objectAtIndex:row];

    return cell;
}

它在Line Cell.TextLabel.text = [Animal objectAtex:row];并告诉我,由于未知的例外“ nsinvalidargumentException”终止应用程序,原因是:' - [__ __ nscfdictionary objectAtexex:]:未识别的选择器已发送到实例

有帮助吗?

解决方案

Animals 您的PLIST中的键是指字典,而不是数组。字典没有保证的命令,因此在特定索引上要求对象没有意义。

除此之外,您还有内存泄漏 - plistDict 分配但从未发布。您是否在代码上运行静态分析仪?

其他提示

[plistDict objectForKey:@"Animals"];

正在返回一个字典,而不是像您期望的那样。您需要查看PLIST文件,以查看数据是否正确。

错误似乎您在打电话 objectAtIndex 在line cell.textlabel.text = [Animal objectAtex:row]的nsdictionary对象上;检查动物在运行时包含的内容。为此,在此行之前使用nslog。 nslog(@“%@”,动物);

好像 animals 是一些 dictionary 你在打电话 objectAtIndex: 上面的方法。 objectAtIndex: : 是 NSArray 方法。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top