在项目详细信息显示屏幕上处理取消编辑的标准方法是什么?
我目前正在开发一个应用程序,该应用程序可以跟踪猫及其相关的芝士汉堡。我用核心数据支持该应用程序。猫和它的芝士汉堡之间存在一对多的关系(允许猫拥有零个或多个芝士汉堡)。
我有一个 UITableViewController,它按名称(姓氏、名字)显示所有猫。当您单击表中的一行时,一个新的 UITableViewController 会被推送到导航控制器上,该控制器显示有关猫的所有信息。就其价值而言,表视图与第一秒分组,其中包含有关猫的信息(名字/姓氏、颜色等)。然后在第二部分中,描述了猫吃的所有芝士汉堡。
右侧导航项是编辑按钮。当用户处于编辑模式时,我隐藏导航栏的后退按钮,将其替换为取消按钮。
我的问题是:关于如何处理编辑屏幕中的数据管理,是否有标准/常见做法/等?我看到它发生在以下两种方式之一:
- 跟踪用户更改的所有内容,然后当他们点击“完成”按钮时,将这些更改复制到“Cat”
NSManagedObject
。 - 使用与 NSManagedObjectContext 关联的 NSUndoManager ,当用户开始编辑时,创建一个新的撤消分组。当他们点击取消按钮时,只需结束分组,然后在
NSUndoManager
上执行撤消即可。
我觉得选项2似乎最实用,但我对此感觉很复杂。对于 iPhone,NSManagedObjectContext
默认情况下没有与之关联的 NSUndoManager
- 我读到它对于 OSX 应用程序是有的。在网上阅读时,我也没有看到太多关于使用与 iPhone 编程相关的 NSManagedObjectContext
的讨论。这让我觉得人们可能正在使用另一种我没有想到的方法。
I'm currently working on an application which keeps tracks of cats and their associated cheeseburgers. I'm backing the application with Core Data. There is a one-to-many relationship between a cat and its cheeseburgers (a cat is allowed to have zero or more cheeseburgers).
I have a UITableViewController which displays all of the cats by name (last name, first name). When you click on a row in the table, a new UITableViewController is pushed onto the navigation controller which displays all of the information about the cat. For what its worth, the table view is grouped with the first second containing information about the cat (first/last name, color, etc). Then in a second section, all the cheese burgers the cat has are described.
The right navigation item is the edit button. When the user is in edit mode, I'm hiding the navigation bar's back button, replacing it with a cancel button.
My question is this: Is there a standard / common practice / etc on how to handle managing the data in the edit screen? I see it happening one of two ways:
- Keep track of all the things the user changes and then when they hit the
done
button, copy those changes to theCat
NSManagedObject
. - Use an
NSUndoManager
associated with theNSManagedObjectContext
and when the user begins editing, create a new undo grouping. When they tap the cancel button, just end the grouping and then perform an undo on theNSUndoManager
.
I feel like option 2 seems most practical, but I have mixed feelings about it. For the iPhone, the NSManagedObjectContext
does not by default have an NSUndoManager
associated with it - I've read that it does for OSX applications. I also don't see much discussion about using the NSManagedObjectContext
in relation to iPhone programming while doing reading on the net. This makes me feel that people may be using another method I haven't thought of.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更常见的 iPhone 应用程序工作流程是根本没有“取消”按钮。大多数应用程序只是将“编辑”按钮变成“完成”按钮。仅当可能丢失的信息难以重现时才考虑取消。
但是,如果您想要“取消”按钮,第一个选项似乎更精简。完成后应用更改。在任何其他情况下,只需丢弃临时更改数据即可。后者不仅在取消时执行,而且在应用程序必须终止时也执行。仅接受显式完成的更改。
A more common iPhone app workflow is to not have a 'Cancel' button at all. Most apps just morph the Edit button into a Done button. Only consider Cancel when the information potentially lost is hard to reproduce.
However, if you want a Cancel button, the first option seems more streamlined. Apply changed on Done. In any other case, just discard the transitory changes data. Do the latter not only on Cancel, but also if the app has to terminate. Only accept the changes with explicit Done.