How to add a navigation controller to a view-based application?(如何将导航控制器添加到基于视图的应用程序中?)
问题描述
是否可以将 UINavigationController 添加到继承自 UIViewController 而不是 UITableViewController 的视图应用程序?是怎么做到的?
Is it possible to add a UINavigationController to a view application that inherits from UIViewController and not UITableViewController? How is it done?
推荐答案
是的,您可以在任何基于视图的应用程序中使用导航控制器,无论是在根级别(例如在 Xcode 中创建基于导航的模板时)还是使用TabBar 根,或任何根.
Yes, you can have Navigation controllers in any view based application, whether at the Root level (like when you create the Navigation-based template in Xcode) or with a TabBar root, or with any Root.
一个例子,展示一个包含导航的模式视图(在我的应用中用于显示一系列表单):
One example, presenting a modal view including navigation (used in my app to display a series of forms):
UIViewController *control = [[MyViewController alloc] initWithNibName: @"MyViewController" bundle: nil];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: control];
[self presentModalViewController: navControl animated: YES];
[control release];
在另一个例子中,如果你想在根级别拥有它,但没有使用 Navigation 模板创建应用程序,在 AppDelegate 的 didFinishLaunching(...) 中:
In another example, if you want to have it at the root level, but didn't create the application with the Navigation template, in the AppDelegate's didFinishLaunching(...):
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: control];
[window setRootViewController: navControl];
[navControl release];
您也可以在 Interface Builder 中设置它,通过设置您使用的 View 控制器的类(UIViewController 替换为 UINavigationController).
You can also set it in Interface Builder, by setting up the class of the View controller you use (UIViewController replaced by UINavigationController).
我希望这能回答你的问题(对之前的讨论感到抱歉).
I hope this answers your question (sorry about the previous discussion).
这篇关于如何将导航控制器添加到基于视图的应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将导航控制器添加到基于视图的应用程序中?
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
