ios – 显示视图控制器时,导航和标签栏丢失

前端之家收集整理的这篇文章主要介绍了ios – 显示视图控制器时,导航和标签栏丢失前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用3D Touch实现主屏幕快捷方式,并且运行良好,但是我目前的方式意味着当快捷方式将用户转到特定的视图控制器时,标签栏和导航栏将丢失.

这是我的代码

  1. func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) -> Bool {
  2. var handled = false
  3.  
  4. if let shortcutType = ShortcutType.init(rawValue: shortcutItem.type) {
  5. let rootViewController = window!.rootViewController
  6.  
  7. switch shortcutType {
  8. case .Favourites:
  9. let storyboard = UIStoryboard(name: "Main",bundle: nil)
  10. let rootController = storyboard.instantiateViewControllerWithIdentifier("favourites") as! FavouritesTableViewController
  11. rootController.parkPassed = DataManager.sharedInstance.getParkByName(NSUserDefaults.standardUserDefaults().stringForKey("currentPark")!)
  12. self.window?.rootViewController = rootController
  13. self.window?.makeKeyAndVisible()
  14.  
  15. handled = true
  16. }
  17. return handled
  18. }

任何人都可以建议我在代码中需要更改的内容

这是右舷布局(指示FavouritesTableViewController):

编辑:

这是我更新的代码

  1. @available(iOS 9.0,*)
  2. func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) -> Bool {
  3. var handled = false
  4.  
  5. if let shortcutType = ShortcutType.init(rawValue: shortcutItem.type) {
  6. switch shortcutType {
  7. case .Favourites:
  8. print("favourites")
  9. let storyboard = UIStoryboard(name: "Main",bundle: nil)
  10. let rootController = storyboard.instantiateViewControllerWithIdentifier("favourites") as! FavouritesViewController
  11. rootController.parkPassed = DataManager.sharedInstance.getParkByName(NSUserDefaults.standardUserDefaults().stringForKey("currentPark")!)
  12.  
  13. let root = UIApplication.sharedApplication().delegate as! AppDelegate
  14. if let navCont = root.window?.rootViewController?.navigationController {
  15. navCont.presentViewController(rootController,animated: true,completion: nil)
  16. } else {
  17. root.window?.rootViewController?.presentViewController(rootController,completion: nil)
  18. }
  19.  
  20. root.window?.makeKeyAndVisible()
  21.  
  22. handled = true
  23. }
  24. }
  25. return handled
  26. }

解决方法

尝试这个:

从应用程序委托获取代理:

  1. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

您想要从故事板中呈现的控制器:

  1. Controller *cont=//get the reference from storyboard either using storyboard ID

然后让您的rootview显示另一个控制器:

  1. [appDelegate.window.rootViewController presentViewController:cont animated:YES completion:^{
  2. DLog(@"presented your view ON TOP of the tab bar controller");
  3. }];

迅速:

  1. var appDelegate: AppDelegate = UIApplication.sharedApplication().delegate()
  2. var cont: Controller = //get the reference form storyboard
  3. appDelegate.window.rootViewController.presentViewController(cont,completion: { DLog("presented your view ON TOP of the tab bar controller")
  4.  
  5. })

你可以在主线程上移动演示内容,如果你喜欢!!!!

猜你在找的iOS相关文章