gpt4 book ai didi

ios - 呈现 View Controller 时缺少导航和标签栏

转载 作者:IT王子 更新时间:2023-10-29 05:37:21 24 4
gpt4 key购买 nike

我正在使用 3D Touch 实现主屏幕快捷方式,它运行良好,但是我目前的方式意味着当快捷方式将用户带到特定的 View Controller 时,标签栏和导航栏会丢失。

这是我的代码:

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

enter image description here

编辑:

这是我更新后的代码:

@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, animated: true, completion: nil)
}

root.window?.makeKeyAndVisible()

handled = true
}
}
return handled
}

最佳答案

试试这个:

从应用委托(delegate)中获取委托(delegate):

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

从 Storyboard 中获取您想要呈现的 Controller :

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

然后让你的 Root View 显示另一个 Controller :

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

swift :

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

})

如果你愿意,你可以在主线程上移动呈现的东西!!!!

关于ios - 呈现 View Controller 时缺少导航和标签栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32827586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com