【发布时间】:2011-06-10 13:33:17
【问题描述】:
我在 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;
}
它在生产线上崩溃了 cell.textLabel.text = [动物 objectAtIndex:row]; 并告诉我 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFDictionary objectAtIndex:]:无法识别的选择器已发送到实例
【问题讨论】:
-
pListPath 的文件内容是什么?
-
试试 NSLogging
[animals objectAtIndex:row],如果不对,试试 NSLoggingself.animals,如果不对,使用:NSLog(@"%@", [plistDict]);。使用它来回溯存储中的问题。代码对我来说似乎没问题。 -
IS 动物是一个数组或字典
-
哦,
pListPath是指向 NSDictionary 的链接吗? -
好的,谢谢大家的快速帮助.. 看来我需要在这里睡一觉.. 但在那之前.. 谁能给我一个如何制作表格的链接,让我们说一些类别例如,在每个类别下,我们都有来自 plist 的字符串列表。我希望这对你来说很容易,再次感谢你拯救了我的一天
标签: iphone uitableview nsexception