2 UIViewController 1 视图

发布于 2024-11-15 08:12:18 字数 573 浏览 11 评论 0原文

这是一个关于 iPhone Objective C 设计的问题。如何让 2 个 UIViewController 管理同一个视图?每个 UIViewController 都会在不同的时间创建,但它们的视图本质上是相同的。

为了帮助解释,这里有一个例子:

假设我有一个 ViewController,它从服务器同步任务列表,允许用户编辑/删除这些任务,并在视图上显示其他信息(如状态消息)等。一次单独的时间,我想使用相同的视图显示这些任务的“只读”列表(因为视图已经创建,tableView已创建,状态消息文本框存在等),但基于不同的事情,我希望这个观点能够发挥作用并更新不同的状态消息。

因此,在这个示例中,我想重用视图,但根据用户所在位置使用 2 个不同的控制器。如果他/她处于编辑模式,则显示操作 VIEW 1 的 UIViewController 1。如果他/她处于读取模式,则显示操作 VIEW 1 的 UIViewController 2。

我想知道如果这是 1,最好的设计方法。可能或者 2.我应该将 VIEW 1 复制为 VIEW 2 并让 UIViewController 2 管理 VIEW 2,即使它们完全相同。

预先感谢您的帮助。

This is a question regarding iPhone objective C design. How can I have 2 UIViewControllers manage the same view? Each UIViewController will be created at different times, but their views are essentially the same thing.

To help explain, here's an example:

Let's say I have one ViewController that synchronizes a list of tasks from the server, allows the user to edit/delete these tasks, and displays other information on the view (like status messages), etc. At a separate time, I want to show a "read-only" list of those tasks using the same view (since the view has already been created, tableView is created, status message textbox is there etc.), but based on different things, I want this view to act differently and update different status messages.

So in this example, I want to reuse the view but use 2 different controllers depending on where the user is. If he/she is in edit mode, display UIViewController 1 which manipulates VIEW 1. If he/she is in read mode, display UIViewController 2 which manipulates VIEW 1.

I'm wondering the best way to design this if this is 1. possible or 2. should I just duplicate VIEW 1 as VIEW 2 and have UIViewController 2 manage VIEW 2, even though they'd be the exact same.

Thanks in advance for your help.

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

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

发布评论

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

评论(1

这样的小城市 2024-11-22 08:12:18

创建一个 UIViewController 基类,每个 UIViewController 类都源自该基类。将所有公共接口元素声明(普通 ivars 或 IBOutlet)放入基类中。如果您使用 InterfaceBuilder,则使文件所有者成为基类。

Create a base UIViewController class that each of yours descend from. Put all of the common interface element declarations (either plain ivars or IBOutlets) in the base class. If you use InterfaceBuilder then make the files owner the base class.

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