objective-c - didSelectRowAtIndexPath 中的 EXC_BAD_ACCESS

标签 objective-c ios uitableview exc-bad-access didselectrowatindexpath

我已经通过以下方式覆盖了我的 UITableViewController didSelectRowAtIndexPath 方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PhotoListViewController *photosViewController = [[PhotoListViewController alloc] initWithStyle:UITableViewStylePlain];

    NSLog(@"Let's see what we got %d", [[fetchedResultsController fetchedObjects] count]);

    Person *person = [fetchedResultsController objectAtIndexPath:indexPath];
    photosViewController.person = person;
    photosViewController.title = [person.name stringByAppendingString:@"'s Photos"];

    [self.navigationController pushViewController:photosViewController animated:YES];

    [photosViewController release];
}

每当我尝试访问 fetchedResultsController 时发生崩溃,我将其设置在此处:

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"person = %@", person];
        fetchedResultsController = [[FlickrFetcher sharedInstance] fetchedResultsControllerForEntity:@"Photo" withPredicate:predicate];
    }
    return self;
}

而且我只在我的dealloc 方法中释放它

最佳答案

似乎在调用 didSelectRowAtIndexPath 方法之前,您的自动释放池已耗尽。您是否尝试过像这样保留 fetchedResultsController:

fetchedResultsController = [[[FlickrFetcher sharedInstance] fetchedResultsControllerForEntity:@"Photo" withPredicate:predicate] retain];

关于objective-c - didSelectRowAtIndexPath 中的 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6626607/

相关文章:

iphone - 开始或停止输入字符时 UITextField 字体大小发生变化

ios - Swift 配置自定义单元格

ios - 当我在 UITableViewController 上滚动时,描述标签消失

ios - 在运行时操纵行为是什么意思?

iphone - 在 iPhone 中创建 "settings"对话框页面的最佳方法

ios - 无法提交 iOS 应用程序以供审核

ios - 无法在 detailTextLabel 中显示 NSString

ios - 使用 PromiseKit 处理错误

ios - UITableViewCell 上的自定义 subview 和滚动问题

ios - 无法使用 CoreBluetooth 显示配对对话框