执行pushViewController 是否需要UINavigationController?
我想我的问题的答案是“是”,但我只是想得到大家的确认。
我有一个 UITableView,当我选择一行时,它应该“滑动”到另一个 UIViewController。 我之前已经在其他应用程序中完成过此操作(并且它们包含了 UINavigationController,尽管在 UITabView 中)。
所以我想知道: 为了使用 self.navigationController PushViewController 是否需要 UINavigationController ?
如果是这样(我再次怀疑这是真的),我必须在哪里定义 UINavigationController? 在 AppDelegate 中?在主/主 UIViewController 中?
I think the answer to my question is "Yes", but i just would like a confirmation from everyone.
I have a UITableView which should "slide" to another UIViewController when i select a row.
I've done this before with other apps (and they've included the UINavigationController, though in a UITabView).
So im wondering:
Is a UINavigationController required in order to use the self.navigationController pushViewController?
If so (which again i suspect to be true), where must I define the UINavigationController?
In the AppDelegate? In the main/primary UIViewController?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您需要有一个 UINavigationController 才能执行 PushViewController。但是,没有任何地方必须定义它。如果整个应用程序中的每个视图控制器都是一个 UINavigationController 的一部分,那么将其放在 App Delegate 中是有意义的。但是,您可以随时分配和使用视图控制器。 (请注意,它是 UIViewController 子类。)您的应用程序中还可以有多个 UINavigationController(这很常见,例如,如果您有选项卡栏)。所以你可以随时创建 UINavigationControllers。
如果您正在寻找呈现其他视图控制器的替代方法,您确实有一些不同的选择。例如,
将允许您从一个视图控制器转换到另一个视图控制器,并且可以在没有 UINavigationController 的情况下使用。但我认为导航控制器通常是从一个视图控制器移动到另一个视图控制器的最佳方式。
Yes, you will need to have a UINavigationController in order to do pushViewController. However, there is no one place where you must define it. If every view controller in your whole application is part of one UINavigationController, then it makes sense to put it in the App Delegate. You can, however, allocate and use a view controller at any time. (Notice that it is a UIViewController subclass.) You can also have multiple UINavigationControllers in your app (which is common, for example, if you have a Tab bar). So you can create UINavigationControllers at any time.
If you are looking for alternate ways of present other view controllers, you do have some different options. For example,
will allow you to transition from one view controller to another view controller, and can be used without a UINavigationController. But I think the Navigation Controller is very often the best way to move from one view controller to another.
简短的回答是:是的。
UINavigationController 的设计目的是管理屏幕上和屏幕外的一堆视图控制器并对其进行动画处理(与其他一些界面元素(例如导航栏或工具栏)结合使用)。传统上,UINavigationController 由 App Delegate 强烈持有和初始化,因为它们被视为最高优先级的根对象。显示
UINavigationController
正确用法的示例类可能如下所示:与往常一样,长的答案是“否”。UINavigationController
可以轻松地重新实现(并且已经多次实现),从而达到很好的效果。它就像子类化 UIViewController 并固定在某种堆栈上(例如 NSMutableArray)一样简单。
The short answer is: Yes.
UINavigationController was designed with the purpose of managing and animating a stack of view controllers on and off the screen (in conjunction with a few other interface elements such as a navigation bar, or a toolbar). Traditionally, UINavigationControllers are strongly held and initialized by the App Delegate, as they are considered a top-priority root object. An example class showing the proper usage of a
UINavigationController
might look like this:The long answer, as always, is No.
UINavigationController can be trivially reimplemented (and it has, many times) to great effect. It's as simple as subclassing UIViewController and bolting on some kind of stack (like an NSMutableArray).