创建“添加”的最佳方法视图控制器
我有一个包含项目对象列表的表视图。当选择一个项目时,它会显示一个详细视图。相当标准。实现“添加”功能(弹出模式视图控制器以输入新值并保存项目)的最佳方法是什么?
目前,我有根视图、详细视图和添加视图的视图控制器。本质上,除了保存和添加视图之外,详细信息视图和添加视图完全相同。添加视图中的取消按钮。是否可以在添加视图中重用详细视图?
最后,在分成几个部分的分组表视图中显示项目属性列表的最佳方法是什么?
感谢您的回复。
I have a table view that contains a list of Project objects. When an item is selected it brings up a detail view. Pretty standard. What is the best way to implement "add" functionality (popup a modal view controller to input new values and save the item)?
Currently I have view controllers for my root view, detail view, and add view. Essentially the detail view and add view are exactly the same except for a save & cancel button in the add view. Is it possible to reuse the detail view in the add view?
Finally, what is the best way to display the list of project properties in a grouped table view separated into sections?
Thank you for your responses.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最有可能的是,您已经向详细视图控制器传递了一个托管对象,该对象应该在详细视图模式下显示。当用户决定添加一个新项目时,只需创建一个空白对象,将其传递给细节控制器并显示它。 (您可能希望将此空白对象插入到另一个“空”托管对象上下文中,以防用户取消添加过程,以避免在这种情况下必须清理主托管对象上下文。)
详细视图控制器还需要一个标志它告诉它是否处于编辑或添加模式,以便它可以相应地调整其控件(并可能将其发送给其所有者的消息委托给其所有者)。在显示控制器之前,您可以将标志设置为适当的值。
Most likely, you are already passing your detail view controller a managed object that it is supposed to display when in detail view mode. When the user decides to add a new project, just create a blank object, pass it to the detail controller and display it. (You might want to insert this blank object into another "empty" managed object context in case the user cancels the add process to avoid having to clean up your main managed object context in that case.)
The detail view controller would also need a flag that tells it whether it is in edit or add mode so it can adjust its controls (and possibly delegate messages it sends to its owner) accordingly. You would set the flag to the appropriate value before you display the controller.
听起来您正在寻找 UINavigationController。 UINavigationController 允许您将新的视图控制器推送到现有的视图控制器之上。它在顶部为您提供了一个导航栏,允许用户返回到根控制器。我认为这是苹果在默认电子邮件应用程序中使用的控制器,举个例子。
关于组织:您设计根视图控制器和详细信息/添加视图控制器。在应用程序委托中,将 UINavigationController 附加到窗口,并将其根控制器设置为要显示的主控制器。然后,该根控制器可以将添加/详细信息控制器推送到堆栈上(当它这样做时,它可以告诉添加/详细信息控制器要显示哪种类型的按钮。)
我无法回答您的分组属性问题,但听起来无论如何,就像一个单独的问题。
It sounds like you're looking for a UINavigationController. The UINavigationController lets you push new view controllers on top of existing ones. It gives you a navigation bar at the top that will allow the user to go back to the root controller. I think it's the kind of controller Apple uses it in the default email application, to give you an example.
Concerning organization: you design your root view controller and a detail/add view controller. In your app delegate, you attach a UINavigationController to the window and you set its root controller to the main controller you want to display. That root controller can then push the add/detail controller onto the stack (and when it does so, it can tell the add/detail controller which types of button to display.)
I can't answer your grouped properties question, but it sounds like a separate question anyway.