UITableView - 如何直接从一个项目的视图移动到另一个项目的视图?
我的应用程序的一部分是笔记部分,有点像 iPhone 的内置笔记应用程序。用户在 UITableView(由 NSFetchedResultsController 控制)中点击他们的注释,UINavigationController 将显示该注释。
目前,如果用户想要查看另一条笔记,他们必须返回 UITableView 并在那里选择它。我想要有向上和向下箭头直接转到下一个/上一个注释。
解决这个问题的最佳方法是什么?我猜我需要返回并以某种方式从 NSFetchedResultsController 获取下一个项目而不显示 UITableView ?如何将其与 UINavigationController 集成?
Part of my app is a notes section, a bit like the iPhone's built-in notes app. The user taps their note in a UITableView (controlled by NSFetchedResultsController), and the UINavigationController shows the note.
At the moment, if the user wants to view another note, they have to go back to the UITableView and choose it there. I would like to have up and down arrows to go straight to the next/previous note.
What is the best way of going about this? I'm guessing I need to go back and get the next item from the NSFetchedResultsController somehow without showing the UITableView? And how do I integrate this with the UINavigationController?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想出了一个相当混乱的解决方案。它只是为了工作,但我确信一定有更优雅和简单的东西。无论如何,这就是我目前正在做的事情。
首先,UITableView 是笔记 UIViewController 的委托。注释的 UIViewController 有一个名为“editingIndexPath”的属性,它是 UITableView 中该注释的索引路径。当用户按下“上一篇笔记”按钮时,将调用以下方法:
然后是 tableViewController 中的委托方法:
这可以工作,但相当不优雅,并且总是会产生“弹出”动画(从右到左),无论是转到下一个音符还是上一个音符。我也用一些核心动画来捏造这一点,但我确信我缺少一种更简单、更好的方法来做到这一点。
I've come up with a rather messy solution. It just about works, but I'm sure there must be something far more elegant and simple. Anyway, here's what I've got working at the moment.
First, the UITableView is a delegate of the note's UIViewController. The note's UIViewController has a property called "editingIndexPath" which is that note's indexPath in the UITableView. When the user presses the "previous note" button, the following method is called:
Then the delegate method in the tableViewController:
This works, but it's rather inelegant, and always results in a "pop" animation (right-to-left), whether it is going to the next note or the previous one. I have fudged that, too, with some core animation, but I'm sure I'm missing a far simpler, better way of doing this.
事实证明答案非常简单——我根本不需要改变观点。我刚刚使用委托从根视图控制器获取了新信息,并更改了当前视图控制器上的所有属性。这些属性之一是 NSIndexPath,因此它知道它出现在根视图表中的位置。
It turned out the answer was really simple - I didn't have to change views at all. I just got the new information from the root view controller using a delegate and changed all the properties on the current view controller. One of those properties is an NSIndexPath, so it knows where in the root view's table it appears.