我正在使用导航 Controller 来访问 UITableView。在这个 UItableView 中,有一个搜索栏和 50 个单元格。当我不滚动然后回击时,应用程序正常运行,但是当我向下滚动 10 个单元格然后回击时,我的应用程序崩溃并出现 EXC_BAD_ACCESS 错误。任何想法都可能是这次崩溃的原因?
在 dealloc 中,我释放了我在头文件中创建的所有对象:
- (void)dealloc
{
[listContent release];
[filteredListContent release];
[tmpCell release];
[cellNib release];
[super dealloc];
}
对于创建单元格的函数,如下所示:(注意我正在使用 searchBar 做一个备用 UItableView)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *kCellID = @"cellID";
ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:kCellID];
if (cell == nil)
{
[self.cellNib instantiateWithOwner:self options:nil];
cell = tmpCell;
self.tmpCell = nil;
}
/*
If the requesting table view is the search display controller's table view, configure the cell using the filtered content, otherwise use the main list.
*/
NSDictionary *dataItem;
if (tableView == self.searchDisplayController.searchResultsTableView)
{
dataItem = [self.filteredListContent objectAtIndex:indexPath.row];
}
else
{
dataItem = [self.listContent objectAtIndex:indexPath.row];
}
// Display dark and light background in alternate rows -- see tableView:willDisplayCell:forRowAtIndexPath:.
cell.useDarkBackground = (indexPath.row % 2 == 0);
// Configure the data for the cell.
cell.icon = [UIImage imageNamed:@"iTaxi.jpeg"];
cell.publisher = [dataItem objectForKey:@"Number"];
cell.name = [dataItem objectForKey:@"Name"];
cell.price = [UIImage imageNamed:@"order-taxi.png"];
return cell;
}
ViewDidUnload 与 dealloc 具有相同的代码
最佳答案
发生该错误是因为您在代码中的某处将 scrollEnabled 设置为“NO”(可能在您激活搜索栏时):
self.tableView.scrollEnabled = NO;
我的意思是,如果您的
searchText length
等于 0
(您刚刚进入搜索模式),您不能禁用 tableview 滚动。希望这对您有所帮助。
祝你好运,良好的编码!
法比奥·德马基
关于objective-c - 滚动 UItableView 并回击时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7482621/