具有转换的非导航应用程序的视图控制器/NIB 架构? [英] View controller/NIB architecture for non-navigation application with transitions?

查看:18
本文介绍了具有转换的非导航应用程序的视图控制器/NIB 架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在修补一个不使用 UINavigation 根视图控制系统的 iPad 应用程序(像许多 iPad 应用程序一样),所以我没有对每个应用程序视图"的自然所有权.我基本上有两个基本视图:文档列表视图和文档编辑视图.

I'm tinkering with an iPad app that (like many iPad apps) doesn't use the UINavigation root view control system, so I don't have natural ownership for each app "view". I essentially have two basic views: a document list view, and a document edit view.

我正在使用 UIView 动画从选定的文档到编辑视图.

I'm playing with UIView animation for getting from a selected document to the edit view.

我在顶部还有一个工具栏,它存在于两个视图"中(带有不同的按钮).

I also have a toolbar on top that exists (with different buttons) in both "views".

因为我没有 UINavigation 为我运行节目,所以我倾向于将越来越多的东西扔到一个 NIB 和一个拥有整个容器的视图控制器中.但现在我想弄清楚如果编辑视图位于不同的 NIB 中,如何从文档列表视图切换到编辑视图,同时保留工具栏.

Because I don't have UINavigation running the show for me, I have a tendency to just throw more and more stuff into one NIB and one view controller that owns the whole container. But now I'm trying to figure out how to segue from the document list view to the edit view if the edit view lives inside a different NIB, preserving the toolbar too.

有人对这样的应用程序结构有想法或经验吗?我发现文档缺乏关于代码/UI 结构的最佳实践,除了微不足道的单屏应用程序或完整的导航应用程序.

Anyone have thoughts or experience on app structures like this? I find the docs lacking on best practices around code/UI structure for anything except trivial one-screen apps or full-on navigation apps.

根据文档,您不应该"让父/子视图控制器拥有相同屏幕"的子组件,但这意味着一个基本上包含整个应用程序的大型喇叭视图控制器,并且不能是对的.

You're not "supposed" to have parent/child view controllers owning subcomponents of the same "screen" according to the docs, but this implies one massive honking view controller that basically contains the whole app, and that can't be right.

不确定是否有正确答案";我正在寻找一些聪明的例子或建议.几个月来没有人接触过这个问题,所以我增加了一个赏金来引起良好的讨论.:)

Not sure if there's a "right answer" to this; I'm looking for some intelligent examples or suggestions. Nobody's touched this question in months, so I'm adding a bounty to generate good chatter. :)

谢谢!

更新:我不是在谈论拆分视图,拆分视图控制器显然可以很好地处理它.相反,请查看 Apple 的 iWork 应用(例如 Pages),它们具有文档列表视图和独立的编辑视图,但它们通过动画相关联.

UPDATE: I'm not talking about a split view, which is clearly well handled by a split view controller. Instead, take a look at Apple's iWork apps (e.g. Pages) which have a document list view and an independent edit view, but these are related by animation.

也许这里真正的问题是:您将如何(或者您甚至可以?)自己构建一个容器"视图控制器,如拆分视图或导航控制器?您是否需要从头开始构建整个该死的东西?我感觉你是,因为在视图控制器之间的交互中似乎隐藏了布线.如果是这样,对此有何看法?

Maybe the real question here is: how would you (or could you even?) build a "container" view controller like the split view or navigation controller, yourself? Are you required to build the whole damn thing from scratch? I sense that you are, because seems to be hidden wiring in the interaction between view controllers. If so, thoughts on this?

推荐答案

我认为视图控制器中唯一隐藏的布线是设置 parentViewController,这是支持为拆分和导航声明的类别所必需的.

I think the only hidden wiring in view controllers is setting parentViewController, which is required to support the categories declared for split and navigation.

视图控制器被设计为嵌套的,每个控制器拥有视图层次结构的一部分.唯一的设计目标是没有视图控制器进入另一个控制器的视图层次结构.父视图控制器通常会调用添加子控制器,以便它可以在其拥有的视图层次结构中设置视图的框架.子视图控制器不应对其控制的视图的超视图执行任何操作,因为它归另一个控制器所有.它不应该设置它控制的视图的中心或框架.

View controllers are designed to be nested, with each controller owning a part of the view hierarchy. The only design goal is that no view controller reach into the view hierarchy of another controller. A parent view controller will usually have some call for adding child controllers so that it can set the frame of the view within the view hierarchy it owns. A child view controller should not do anything to the superview of the view it controls, as that is owned by another controller. Not should it set the center or frame of the view it controls.

例如,一个导航控制器有一个push方法,它移除之前的控制器视图,添加新的控制器视图,并设置新添加的视图的框架.一般来说,父视图控制器可以自由设置子控制器视图的框架,但不能设置边界.

For example, a navigation controller has a push method, in which it removes the previous controller view, adds the new controller view, and sets the frame of the newly added view. In general, a parent view controller is free to set the frame of the view of a child controller, but not the bounds.

如果你想改变导航控制器的动画,我认为你应该首先用一个animated:参数实现每个方法.设置动画,然后在提交动画之前调用 super 并关闭动画标志.

If you want to change the animation of a navigation controller, I think you would start by implementing every method with an animated: argument. Set up your animation then call super with the animated flag off before committing the animation.

这篇关于具有转换的非导航应用程序的视图控制器/NIB 架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆