简体   繁体   English

NSFetchResultsController iOS4

[英]NSFetchResultsController iOS4

I'm only getting this error in my app since upgrading to ios4. 自升级到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 . 返回NULL

Why would this be? 为什么会这样?

newsDetailController.news isn't NULL . newsDetailController.news不是NULL

Edit: 编辑:

To highlight this: 要突出这一点:

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

... returns NULL, even though: ...返回NULL,即使:

[self.fetchedResultsController objectAtIndexPath:indexPath]

...returns an object. ...返回一个对象。

Are you positive that the news property (I am guessing it is a property on your detail view controller) is not nil ? 您是否肯定新闻属性(我想这是您的详细信息视图控制器上的属性)不是nil Are you confirming your assumptions that both newsDetailController and newsDetailController.news are not nil ? 您是否在确认newsDetailControllernewsDetailController.news都不nil假设?

iOS4 has brought with it proper non-fragile iVars. iOS4带来了适当的非脆弱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. 如果您在“工作”之前在@property声明中做了一些不正确的操作,那么对iOS4的更改现在可能会捕获该错误。

Step one, walk the code in the debugger and make sure everything has a value that you expect to have a value. 第一步,在调试器中遍历代码,并确保所有内容都具有您期望具有的值。

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 eg 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. 在这种情况下,您还需要确保news是代表完整实体的对象。 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. 如果使用键路径作为要在索引路径处返回的对象,则它必须是关系另一端的对象,它不能是保存属性数据的对象(例如NSString )。

If news is a relationship, the FRC walks the object graph and returns the indexPath. 如果news是关系,则FRC遍历对象图并返回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. 但是,如果news只是一个属性,则它没有indexPath,因为indexPaths仅描述到对象图中实体的路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM