使用没有UITableViewController的NSFetchedResultsController [英] Using an NSFetchedResultsController without a UITableViewController

查看:118
本文介绍了使用没有UITableViewController的NSFetchedResultsController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题,试图使用NSFetchedResultsController没有相应的UITableViewController。



根据苹果文档



NSFetchedResultsController旨在有效地管理从Core Data fetch请求返回的结果以提供UITableView对象的数据。



所以我首先研究了如果没有UITableViewController,使用NSFetchedResultsController建议并遇到此Stackoverflow post ,其中总结出,至少在某些情况下,它不是一个坏主意。



但现在我遇到了一个问题,当一个相应的UITableViewController不存在时,NSFetchedResultsController的行为不同。问题是当UITableViewController不存在时,NSFetchedResultsController返回的对象没有IndexPath。我在 stackoverflow post 中记录了此问题。 (注意这是一个简化的问题,在某些情况下,对象有IndexPaths,但我遇到了足够的问题,相信期望 IndexPaths没有UITableViewController是一个坏主意。)



如果没有IndexPaths,我不能按照它们的排序顺序访问返回的对象,并且我不能访问特定的对象。所以我正在寻找的是一种方法来获得NSFetchedResults控制器返回对象与IndexPaths,或另一种方式访问​​对象。 (或者也许我不应该使用NSFetchedResultsController)



重新替换方法,一个工作是将fetchedObjects传递给一个数组,然后工作与该数组。但是在我创建FRC对象的新指针的经验总是导致问题。我想每次我试图用我自己的指针保留一个NSManagedObject它最终导致一个错误。



FYI,我想创建的是一个导航栏类似于照片中的导航栏。如果你想象你可以动态添加照片到照片应用程序,那么这将是有意义的,由棒状图中的照片由NSFetchedResultsController管理 - 以便添加新的照片将动态添加到栏的末端,很像如何添加一个新的对象动态添加到UITableView。



感谢任何想法,你可以帮助我!



UPDATE 此问题(暂时)通过使用 - [NSFetchedResultsController fetchedObjects] objectAtIndex:]

解决方案

这是通过使用 - [NSFetchedResultsController fetchedObjects] objectAtIndex:]



解决的方法NSFetchedResultsController作为一个管理对象集合,类似于NSArray,它易于使用。事实上,它暴露了一个名为fetchedObjects的只读属性,它的类型为NSArray,使得访问它所获取的对象变得更加容易。


I'm running into problems trying to use a NSFetchedResultsController without a corresponding UITableViewController.

According to Apples documentation:

"NSFetchedResultsController is intended to efficiently manage the results returned from a Core Data fetch request to provide data for a UITableView object."

So I first researched whether using the NSFetchedResultsController without a UITableViewController was advisable and encounter this Stackoverflow post where it is concluded that, at least in some circumstances, it's not a bad idea.

But now I've encountered an issue where the NSFetchedResultsController behaves differently when a corresponding UITableViewController isn't present. The problem is when a UITableViewController is not present, the objects returned by the NSFetchedResultsController do not have IndexPaths. I've documented this problem in a stackoverflow post. (Note this is a simplification of the issue, in some circumstances the objects do have IndexPaths, but I've encountered enough problems to believe that expecting IndexPaths without a UITableViewController is a bad idea.)

Without IndexPaths, I can't access the returned objects in their sort order, and I can't access specific objects. So what I am looking for is either a way to get the NSFetchedResults controller to return objects with IndexPaths, or an alternative way to access the objects. (Or perhaps I shouldn't be using an NSFetchedResultsController at all?)

Re alternative methods, one work around would be to pass the fetchedObjects to an array, and then work with that array. But in my experience creating new pointers to FRC objects always causes problems. I think every time I've ever tried to retain an NSManagedObject with my own pointers it has eventually caused a bug.

FYI, what I am trying to create is a navigation bar similar to the navigation bar in Photos. If you imagined you could dynamically add photos to the Photos application, then it would make sense for the photos in the bar to managed by an NSFetchedResultsController -- so that adding a new photo would be dynamically added to the end of the bar, much like how adding a new object is dynamically added to a UITableView.

Thanks for any ideas you might be able to help me out with!

UPDATE this issue is (tentatively) solved by using -[NSFetchedResultsController fetchedObjects] objectAtIndex:]

解决方案

This is solved by using -[NSFetchedResultsController fetchedObjects] objectAtIndex:]

NSFetchedResultsController behaves as a collection of managed objects, similar to an NSArray, which makes it easy to use. In fact, it exposes a read-only property called fetchedObjects that is of type NSArray to make things even easier to access the objects it fetches.

这篇关于使用没有UITableViewController的NSFetchedResultsController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆