我正在尝试从 AppDelegate 调用一个函数,并使用该函数尝试执行转场。
func doSegue (_ verification : Bool) {
if verification {
print ("Segue performed")
LoginVC ()
.performSegue (withIdentifier: "tosignup", sender: nil)
}
else { print("An error occured while login") }
}
func btnremove () {
print ("Segue performed 1")
loginbtn.isHidden = true doSegue (true)
}
这些是超出执行范围的错误。
最佳答案
如果您没有在 LoginVC 中的prepareForSegue 中执行任何特殊操作,您可以在 AppDelegate 中启动 Root View Controller :
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if (verification) {
let initialViewController = storyboard.instantiateViewController(withIdentifier: "LoginVC")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
} else {
let initialViewController = storyboard.instantiateViewController(withIdentifier: "SignupformVC")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
}
return true
}
您还应该为 View Controller 设置标识符。
关于ios - 从 AppDelegate 调用函数并使用该函数执行 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55086591/