didSelectRowAtIndexPath 中的 EXC_BAD_ACCESS

发布于 2024-11-19 00:48:12 字数 1255 浏览 6 评论 0原文

我已经用以下方式覆盖了我的 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 方法中释放它

I have overwritten my UITableViewController didSelectRowAtIndexPath method the following way:

- (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];
}

Whenever I try to access the fetchedResultsController I get the crash, I set it here:

- (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;
}

And I only release it in my dealloc method

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥抱没勇气 2024-11-26 00:48:12

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

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

Seems like your autorelease pool is getting drained before your didSelectRowAtIndexPath method is called. Did you try retaining the fetchedResultsController like so:

fetchedResultsController = [[[FlickrFetcher sharedInstance] fetchedResultsControllerForEntity:@"Photo" withPredicate:predicate] retain];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文