如何从我的AppDelegate呈现一个视图控制器,并在该视图中添加一个导航栏,并带有前一个视图的后退按钮?我需要从AppDelegate以编程方式执行此操作。目前我可以从那里推出一个控制器,但它并不像一个segue。它没有添加带有后退按钮的导航栏。现在我知道我应该能够自己添加一个,但是当我这样做时它会被隐藏起来。目前我正在使用pushViewController()
,但我认为这不是最佳方式。
答案 0 :(得分:0)
如果你想在NavigationController
中添加appDelegate
,你可以这样做,这样,你的viewcontroller从故事板加载
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let vc = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("vc") as! ViewController
let nav = UINavigationController(rootViewController: vc)
self.window?.rootViewController = nav
self.window?.backgroundColor = UIColor.whiteColor()
self.window?.makeKeyAndVisible()
return true
}
答案 1 :(得分:0)
我认为有些东西是相似的,如果不相同的话:
高级视图
UIViewController
(ViewController.swift)嵌入在UINavigationController
UIViewController
上的按钮会转到带有自定义类的视图:ExistingLocationViewController
- UITableViewController
UINavigationController
工具栏中的其中一个按钮(添加新位置)会使用另一个自定义类进行查看:NewLocationViewController
- UIViewController
CLLocationManagerDelegate
UITextFieldDelegate
解决强>
override func viewDidLoad() {
super.viewDidLoad()
//...
navigationController?.isNavigationBarHidden = false
navigationController?.isToolbarHidden = false
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated) // #=# not sure if this is needed
navigationController?.isNavigationBarHidden = false
navigationController?.isToolbarHidden = false
}
您实际上可以省略viewWillDisappear
中的最后两行,或者甚至可以省略整个override
功能
最终结果(对我来说)如下所示: