0

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

8vius
  • 5,786
  • 14
  • 74
  • 136
  • Please post any relevant crash information. Console output, crash log, and make sure NSZombieEnabled is on – Joe Jul 08 '11 at 15:26
  • I get no crash info, it just halts in my main on this line int retVal = UIApplicationMain(argc, argv, nil, nil); and says EXC_BAD_ACCESS – 8vius Jul 08 '11 at 15:32
  • Can you tell me how I set NSZombieEnabled? – 8vius Jul 08 '11 at 15:36
  • Ok, I set NSZombieEnabled and my fetchedObjects are not there it seems, let me check a little further – 8vius Jul 08 '11 at 15:43
  • 2
    The issue was simply not retaining fetchedResultsController, but NSZombieEnabled will help you find issues like this faster. http://stackoverflow.com/questions/2190227/how-do-i-set-nszombieenabled-in-xcode-4 – Joe Jul 08 '11 at 15:44

1 Answers1

5

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];
Perception
  • 79,279
  • 19
  • 185
  • 195
  • If you check the 2nd block of code I posted I do that in my initWithStyle method – 8vius Jul 08 '11 at 15:40
  • The key there is the call to retain, your fetchedResultsController is not guaranteed to live long enough to be useful outside of your init method unless you retain it. – Joe Jul 08 '11 at 15:45
  • I thought setting the property as (nonatomic, retain) did that – 8vius Jul 08 '11 at 15:51
  • You are not using the property unless you specify `self`. `self.fetchedResultsController` would not require you to retain because it would of used the property instead of the instance variable like you are now. – Joe Jul 08 '11 at 16:10