【发布时间】:2013-05-17 06:37:58
【问题描述】:
当我在 aepub 阅读器中运行搜索功能时,我的应用程序崩溃了。以index方法进入cellfor行,执行NSLOg(@"%@",hit.neighbourText)时显示异常。
(UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.adjustsFontSizeToFitWidth = YES;
NSLog(@"indexpath%d",indexPath.row);
NSLog(@"%@",[results objectAtIndex:[indexPath row]]);
hit = (SearchResult*)[results objectAtIndex:[indexPath row]];
if([results count]>0) {
NSLog(@"%@",hit.neighboringText);
cell.textLabel.text = [NSString stringWithFormat:@"...%@...", hit.neighboringText];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Chapter %d - page %d", hit.chapterIndex, hit.pageIndex+1];
return cell;
}
}
我得到了 hit.neighboringText 的一些价值,但在那之后,我重新加载了我的 tableview,然后会引发以下异常,为什么?
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[__NSCFConstantString 相邻文本]:无法识别的选择器发送到实例 0x1481c4' *** 首先抛出调用栈:
【问题讨论】:
-
hit是什么...很大的可能是它在访问时被 nil/released/deallocated。 -
在 NSLog(@"%@",hit);检查是否获取 nil 或 SearchResult 对象
-
可能是
hit不是你的modal object (SearchResult)。尝试打印NSLog("%@", [hit class]);。如果是String,您必须考虑查看您的results数组。
标签: ios objective-c uitableview