【问题标题】:Creating a navigation controller using single view application使用单视图应用程序创建导航控制器
【发布时间】:2015-11-18 16:40:25
【问题描述】:

我想使用导航控制器创建一个单视图应用程序。

我怎样才能做到这一点或发布相同的链接?

【问题讨论】:

  • 为什么要在单视图应用程序中使用导航控制器?
  • 这就是我的教授要我做的事情
  • 你的答案是如何使用情节提要,但我想不用情节提要
  • 我有一个新问题,我会在那边标记你。如果你能回答这个问题,那就太好了
  • 我去看看。我以为我把代码放在了故事板中。滚动到帖子底部。

标签: objective-c xcode


【解决方案1】:

我不知道您为什么希望在单视图应用程序中使用导航控制器,但您可以这样做。

如果您使用 Storyboard,请选择初始 ViewController 上的视图控制器图标,然后:

转到编辑器 -> 嵌入 -> 导航控制器

这将添加您的导航控制器。

如果您想以编程方式执行此操作,那么您将希望在AppDelegate 的方法didFinishLaunchingWithOptions 中实现此代码:

UIViewController *bbp=[[UIViewController alloc]initWithNibName:@"UIViewController" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
// [self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
  [self.navigationController pushViewController:passcodeNavigationController animated:YES];
  [passcodeNavigationController release];

如果你曾经对 Swift 感兴趣,我找到了this thread,并且接受的答案似乎相当不错:

self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
var nav1 = UINavigationController()
var mainView = ViewController(nibName: nil, bundle: nil) //ViewController = Name of your controller
nav1.viewControllers = [mainView]
self.window!.rootViewController = nav1
self.window?.makeKeyAndVisible()

这是来自 Objective-C 的转换代码(可能有错误):

var bbp: UIViewController = UIViewController(nibName: "UIViewController", bundle: nil)
var passcodeNavigationController: UINavigationController = UINavigationController(rootViewController: bbp)
// [self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
navigationController.pushViewController(passcodeNavigationController, animated: true)
passcodeNavigationController

【讨论】:

    猜你喜欢
    • 2012-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-15
    相关资源
    最近更新 更多