didSelectRowAtIndexPath中的EXC_BAD_ACCESS

8vi*_*ius 0 exc-bad-access objective-c uitableview didselectrowatindexpath ios

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];
}
Run Code Online (Sandbox Code Playgroud)

每当我试图访问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;
}
Run Code Online (Sandbox Code Playgroud)

我只用我的dealloc方法发布它

Per*_*ion 5

在调用didSelectRowAtIndexPath方法之前,似乎您的自动释放池已经耗尽.您是否尝试保留fetchedResultsController,如下所示:

fetchedResultsController = [[[FlickrFetcher sharedInstance] fetchedResultsControllerForEntity:@"Photo" withPredicate:predicate] retain];
Run Code Online (Sandbox Code Playgroud)