今天我有一个扩展,其中有一个按钮可以启动该应用程序,当从该按钮启动应用程序时,导航控制器变为无
我不知道为什么会这样?
这是我在appdelegate中的代码:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
var storyBoard: UIStoryboard!
var mainViewController: MainViewController!
self.window = UIWindow(frame: UIScreen.main.bounds)
if UserDefaults.getLanguage() == "ar" {
storyBoard = UIStoryboard(name: "MainAR", bundle: nil)
} else {
storyBoard = UIStoryboard(name: "Main", bundle: nil)
}
let viewController = storyBoard.instantiateViewController(withIdentifier: "swRevealController") as! SWRevealViewController
mainViewController = storyBoard.instantiateViewController(withIdentifier: "mainView") as! MainViewController
self.window?.rootViewController = viewController
self.window?.makeKeyAndVisible()
viewController.setFront(mainViewController, animated: true)
if url.scheme == "open"
{
switch url.host
{
case "1"?:
mainViewController.isTaxi = true
break
case "2"?:
mainViewController.isPfp = true
break
case "3"?:
mainViewController.isDarbi = true
break
default:
break
}
}
return true
}
请任何人可以帮助吗?
答案 0 :(得分:0)
这是因为该行覆盖了故事板导航
self.window?.rootViewController = viewController
您必须将其嵌入这样的导航中
self.window?.rootViewController = UINavigationController(rootViewController: viewController)
编辑:此行init isTaxi之前
mainViewController.isTaxi = // set it to true / false
viewController.setFront(mainViewController, animated: true)
//
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
var storyBoard: UIStoryboard!
var mainViewController:MainViewController!
self.window = UIWindow(frame: UIScreen.main.bounds)
if UserDefaults.getLanguage() == "ar" {
storyBoard = UIStoryboard(name: "MainAR", bundle: nil)
} else {
storyBoard = UIStoryboard(name: "Main", bundle: nil)
}
mainViewController = storyBoard.instantiateViewController(withIdentifier: "mainView") as! MainViewController
if url.scheme == "open"
{
switch url.host
{
case "1"?:
mainViewController.isTaxi = true
break
case "2"?:
mainViewController.isPfp = true
break
case "3"?:
mainViewController.isDarbi = true
break
default:
break
}
}
let viewController = storyBoard.instantiateViewController(withIdentifier: "swRevealController") as! SWRevealViewController
viewController.setFront(mainViewController, animated: true)
self.window?.rootViewController = UINavigationController(rootViewController: viewController)
self.window?.makeKeyAndVisible()
return true
}