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

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

这是我的代码

func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) -> Bool {
    var handled = false

    if let shortcutType = ShortcutType.init(rawValue: shortcutItem.type) {
        let rootViewController = window!.rootViewController

        switch shortcutType {
        case .Favourites:
            let storyboard = UIStoryboard(name: "Main",bundle: nil)
            let rootController = storyboard.instantiateViewControllerWithIdentifier("favourites") as! FavouritesTableViewController
            rootController.parkPassed = DataManager.sharedInstance.getParkByName(NSUserDefaults.standardUserDefaults().stringForKey("currentPark")!)
            self.window?.rootViewController = rootController
            self.window?.makeKeyAndVisible()

            handled = true
        }
    return handled
}

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

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

编辑:

这是我更新的代码

@available(iOS 9.0,*)
func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) -> Bool {
    var handled = false

    if let shortcutType = ShortcutType.init(rawValue: shortcutItem.type) {
        switch shortcutType {
        case .Favourites:
            print("favourites")
            let storyboard = UIStoryboard(name: "Main",bundle: nil)
            let rootController = storyboard.instantiateViewControllerWithIdentifier("favourites") as! FavouritesViewController
            rootController.parkPassed = DataManager.sharedInstance.getParkByName(NSUserDefaults.standardUserDefaults().stringForKey("currentPark")!)

            let root = UIApplication.sharedApplication().delegate as! AppDelegate
            if let navCont = root.window?.rootViewController?.navigationController {
                navCont.presentViewController(rootController,animated: true,completion: nil)
            } else {
                root.window?.rootViewController?.presentViewController(rootController,completion: nil)
            }

            root.window?.makeKeyAndVisible()

            handled = true
        }
    }
    return handled
}

解决方法

尝试这个:

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

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

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

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

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

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

迅速:

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

 })

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

原文链接:https://www.f2er.com/iOS/330268.html

猜你在找的iOS相关文章