所以,我已经把所有的事情都做好了。当按下短键动作时,我会在控制台中得到正确的打印。我从这里要去哪里?我搞不懂..。
这是我在中的代码
var quicklaunch: Bool!
var viewName: String?
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
viewName = shortcutItem.type
quicklaunch = true
completionHandler(quicklaunch)
}
func applicationDidBecomeActive(application: UIApplication) {
if quicklaunch == true {
quicklaunch = false
if viewName == "Messages" {
let rootViewController = self.window?.rootViewController
let popUpController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FriendsVC")
rootViewController?.present(popUpController, animated: true, completion: nil)
print("Worked")
}
}
}
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
if quicklaunch == false {
quicklaunch = true
if viewName == "Messages" {
let rootViewController = self.window?.rootViewController
let popUpController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FriendsVC")
rootViewController?.present(popUpController, animated: true, completion: nil)
print("Worked")
}
}
}如何让它弹出到正确的视图控制器?
发布于 2017-05-30 07:36:10
您可以获取rootViewController,然后以模式方式呈现所需的viewController (如果rootViewController是UINavigationController,则将其推到导航堆栈上)。与…有关的东西
let rootViewController = self.window?.rootViewController
let popUpController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "???") as! ???
rootViewController.present(popUpController, animated: true, completion: nil)用相应的值替换???
编辑
在AppDelegate中创建一个名为quickLaunch的布尔变量和一个字符串变量viewName。然后更新以下两种方法
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
viewName = shortcutItem.type
quickLaunch = true
completionHandler(quickLaunch)
}
func applicationDidBecomeActive(application: UIApplication) {
if quickLaunch == true {
quickLaunch = false
//PRESENT YOUR VIEW MODALLY HERE
}
}https://stackoverflow.com/questions/44254516
复制相似问题