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")

 })

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

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...