如何从appdelegate打开弹出窗口?

问题描述 投票:0回答:1

我有一些任务要做,我正在努力。我必须在应用程序开始时打开一个模式弹出窗口,但是当我尝试加载弹出窗口时,我的出口总是为零,我尝试了几种不同的加载视图的方法,它的出口总是为零。有什么建议?在这里我发布一些代码

  func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        window = UIWindow(frame: UIScreen.main.bounds)
        window?.makeKeyAndVisible()

        window?.rootViewController = FirstLaunchViewController()
   }

这是我的appDelegate。

 class StartNavViewController: UINavigationController {
  override func viewDidLoad() {
    super.viewDidLoad()

    perform(#selector(showPopUp), with: nil, afterDelay: 0.01)

}

@objc func showPopUp(){

    let first = FirstLaunchViewController()

    present(first, animated: true, completion: nil)

  }

}

这是我的起始导航控制器,我试图加载我的FirstLaunchVC。我也试过准备和执行一个segue,结果完全相同=出口是零。在FirstLaunchVC中,我在viewdidload方法中为我的outlet设置了一些值,如果需要,我可以发布一些代码以便更清晰。

我对Swift相当新,所以要尽可能准确。非常感谢你提前。

swift popup appdelegate
1个回答
1
投票

如果您的vc在故事板内

let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "VCID") as! FirstLaunchViewController 
window?.rootViewController = vc
window?.makeKeyAndVisible()
© www.soinside.com 2019 - 2024. All rights reserved.