Ios 导航控制器从今天起变为零
我有一个today扩展,其中有一个启动应用程序的按钮,当从该按钮启动应用程序时,导航控制器变为零 我不知道为什么会这样 这是我在appdelegate中的代码:Ios 导航控制器从今天起变为零,ios,swift,uinavigationcontroller,appdelegate,today-extension,Ios,Swift,Uinavigationcontroller,Appdelegate,Today Extension,我有一个today扩展,其中有一个启动应用程序的按钮,当从该按钮启动应用程序时,导航控制器变为零 我不知道为什么会这样 这是我在appdelegate中的代码: func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { var storyBoard: UIStoryboard! var mainV
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
}
任何人都可以帮忙吗?这是因为这行代码编写了故事板导航
self.window?.rootViewController = viewController
您必须将其嵌入这样的导航中
self.window?.rootViewController = UINavigationController(rootViewController: viewController)
编辑:在这一行之前初始化isTaxi
mainViewController.isTaxi = // set it to true / false
viewController.setFront(mainViewController, animated: true)
//
你在哪里设置导航控制器?我没有在这里设置,当我通过扩展中的按钮打开应用程序时,应用程序按预期启动。但在应用程序内部,我有一个按钮,它使用导航控制器按下另一个viewcontroller。由于导航控制器为零。我不工作。使用self.window?.rootViewController=UINavigationController(rootViewController:mainViewController)注释不用于扩展讨论;这段对话已经结束。
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
}