views:

36

answers:

2

I'm only getting this error in my app since upgrading to ios4.

newsDetailController.news = (News *)[self.fetchedResultsController objectAtIndexPath:indexPath];
NSLog(@"\n Indexpath of details news before pass = %@", [self.fetchedResultsController indexPathForObject:newsDetailController.news]);

Basically, this:

[self.fetchedResultsController indexPathForObject:newsDetailController.news])

returns NULL.

Why would this be?

newsDetailController.news isn't NULL.

Thanks

Dan

Edit:

To highlight this:

NSLog(@"\n Indexpath of detailssss news before pass = %@", [self.fetchedResultsController indexPathForObject:[self.fetchedResultsController objectAtIndexPath:indexPath]]);

... returns NULL, even though:

[self.fetchedResultsController objectAtIndexPath:indexPath]

...returns an object.

A: 

Usually when something goes wonky with the indexes of a fetched results controller, it's because a mistake as been made with the section info e.g. adding a section key when you don't have sections. You should also not use the cache until you resolve the problem.

In this case, you also want to make sure that news is an object that represents a complete entity. If you use a keypath as the object to return at the indexpath, it has to be an object at the other end of a relationship, it can't be an object (such as an NSString) that holds the data of an attribute.

If news is a relationship, the FRC walks the object graph and returns the indexPath. However, if news is just an attribute, then it has no indexPath because indexPaths only describe the route to an entity in the object graph.

TechZen
+1  A: 

Are you positive that the news property (I am guessing it is a property on your detail view controller) is not nil? Are you confirming your assumptions that both newsDetailController and newsDetailController.news are not nil?

iOS4 has brought with it proper non-fragile iVars. If you were doing something incorrect in your @property declarations before that "worked" then the changes to iOS4 may now be catching that mistake.

Step one, walk the code in the debugger and make sure everything has a value that you expect to have a value.

Marcus S. Zarra