objective-c - 滚动 UItableView 并回击时应用程序崩溃

标签 objective-c ios xcode

我正在使用导航 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/

相关文章:

ios - 使用 Flurry Analytics 跟踪页面/屏幕浏览量

ios - SKEmitterNode 没有从父级中删除自己?

ios - 如何创建比设备屏幕大的 UIImage?

ios - 如何填充 UITableView 中的部分

xcode - Swift 中递归引用自身的函数

ios - 具有多个自定义单元格滚动和重用问题的 uitableview

objective-c - 如何使用 Gdata for iOS App 将视频从私有(private)视频更改为公共(public) YouTube API

iphone - 在 Resources 文件夹下添加 iOS 图标和启动图像

xcode - 如何知道应用程序是否首次在 Mac 上运行

Ruby gem Xcodeproj 在项目保存时抛出异常