ios - 从 AppDelegate 调用函数并使用该函数执行 segue

标签 ios swift uiviewcontroller appdelegate

我正在尝试从 AppDelegate 调用一个函数,并使用该函数尝试执行转场。

My Storyboard
(点击图片可放大)

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

这些是超出执行范围的错误。

These are the errors which came beyond execution.

最佳答案

如果您没有在 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/

相关文章:

ios - 创建没有代码签名的 iOS 应用程序,卡住安装应用程序

ios - 如何从 XCode 6 应用程序提交菜单中删除二进制文件?

cocoa-touch - UITableViewCell 在显示时没有刷新?

ios - 使用 slider 选择 View 背景的颜色

iphone - UIViewController 中的继承

ios - 为什么我不能在 UIPageViewController 中设置 View Controller ?

ios - 是否可以更改 AVPlayer 的背景颜色?如果是,如何?

swift - Double 的字节顺序可以安全地反转吗?

ios - 谷歌驱动器 API : Insufficient Permission iOS

objective-c - UITextField.text 一直返回 null