如何单击/迭代 coreData 实例

发布于 2024-12-19 23:28:20 字数 395 浏览 1 评论 0原文

这是关于 如何像在邮件中那样进行下一个详细视图的另一个问题-我的应用程序。在那里,我想知道如何用数组解决这个问题。

现在我正在使用 coreData。我有一个名为 EntityAlphabet 的实体,例如,它有 5 个属性。属性在这里并不重要。 在 DetailView 中,我想迭代这个实体。 我该怎么做?

我想“切换”detailView 中的实体。

顺便说一句:我正在使用 NSFetchedResultsController 填充我的 tableView。

here is another question about how to next detailView like in Mail-App from me. There, i wanted to know how to solve that with an array.

Now i am using coreData. I have an entity named EntityAlphabet with - for example - 5 attributes. The attributes doesnt matter here.
In the DetailView, i want to iterate this Entity. How can i do that?

I want to "switch" the entitys in the detailView.

BTW: I am populating my tableView with NSFetchedResultsController.

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

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

发布评论

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

评论(2

若言繁花未落 2024-12-26 23:28:20

我有完全相同的情况,我只是将一个托管对象数组传递给了详细视图。然后,根据他们在详细视图上按下的向上/向下箭头,我从数组中选择适当的对象。因此,它与您提供的链接中的解决方案类似。要获取对象数组,请在 didSelectRowForIndexPath: 方法中执行以下操作:

// Assumes your detail view controller has a an NSArray ivar and property setup 
detailViewController.alphabetObjects=[self.fetchedResultsController fetchedObjects];

该解决方案显然技术含量较低,由于当时(即 2 年前)缺乏知识,我实现了它。现在,我可以想到一些其他的方法来做到这一点。

  1. 利用块回调由 NSFetchedResultsController 管理的 tableView。因此,当您的 didSelectRowAtIndexPath 方法时,您将为detailViewController提供一个块,该块基本上采用indexPath并从您的NSFetchedResultsController返回新的托管对象。
  2. 创建 tableViewController 实现的协议。通过协议的各种方法,您可以请求新对象以及更新detailViewController UI。即查询它是否是托管对象集中的第一个或最后一个对象。

希望这有帮助。祝你好运

I have the exact same situation and I just passed an array of managedObjects to the detailView. Then, based upon which up/down arrow they press on the detail view, I select the appropriate object from the array. So it would be similar to the solution from the link you provided. To get the array of objects, in your didSelectRowForIndexPath: method do something along the lines of the following:

// Assumes your detail view controller has a an NSArray ivar and property setup 
detailViewController.alphabetObjects=[self.fetchedResultsController fetchedObjects];

This solution is decidedly low tech and I implemented it because of my lack of knowledge at the time, i.e. 2 years ago. Now, I could think of a couple of additional ways of doing it.

  1. Utilize block call backs to the tableView being managed by the NSFetchedResultsController. So when your didSelectRowAtIndexPath method, you would provide the detailViewController with a block that basically takes an indexPath and returns the new managedObject from your NSFetchedResultsController.
  2. Create a protocol that the tableViewController implements. Through the various methods of the protocol you can request the new object as well as update the detailViewController UI. i.e. queries whether or not it is the first or last object in the set of managedObjects.

Hope this helps. Good luck

吻泪 2024-12-26 23:28:20

您可以以类似的方式使用 NSFetchedResultsController。尝试调用 - (id)objectAtIndexPath:(NSIndexPath *)indexPath。将您已在 - (IBAction)nextRow:(id) 发送方 中使用的 newIndexPath 传递给它。

You can use NSFetchedResultsController in a similar manner. Try calling - (id)objectAtIndexPath:(NSIndexPath *)indexPath. Pass it the newIndexPath you are already using in your - (IBAction)nextRow:(id) sender.

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