gpt4 book ai didi

ios - 加载 LaunchScreen 后显示 ViewController

转载 作者:行者123 更新时间:2023-11-30 12:15:09 25 4
gpt4 key购买 nike

我正在尝试为我的应用程序创建一个演练(简介)。我正在使用 BWWalkthrough 来做到这一点。如果想在单击按钮后打开此 View Controller ,它可以工作(如下面的代码所示)。但我不想这样做。我想在加载启动屏幕后打开此 View Controller 。

当我单击母版页的“是初始 View Controller ”并在 viewDidLoad 方法中添加以下代码时,我只能看到母版页,但看不到附加到母版页的 View Controller (page_one、page_two ...) 。可能我必须在 AppDelegate 中编写一些代码,但我不知道它是怎么回事

如何解决这个问题?

@IBAction func testButton(_ sender: Any) {

let goStoryboard = UIStoryboard(name: "Main", bundle: nil)
let walkthrough = goStoryboard.instantiateViewController(withIdentifier: "master") as! BWWalkthroughViewController
let page_one = goStoryboard.instantiateViewController(withIdentifier: "page1") as UIViewController
let page_two = goStoryboard.instantiateViewController(withIdentifier: "page2")as UIViewController
let page_three = goStoryboard.instantiateViewController(withIdentifier: "page3")as UIViewController

**// Attach the pages to the master**
walkthrough.delegate = self
walkthrough.add(viewController:page_one)
walkthrough.add(viewController:page_two)
walkthrough.add(viewController:page_three)

self.present(walkthrough, animated: true, completion: nil)

}

最佳答案

首先,转到主 Storyboard并创建一个新的 View Controller 。您还应该创建一个 View Controller 类。这将是您的主屏幕 Storyboard,您将其设置为初始 View Controller 。

在您之前创建的类中,您可以放置​​以下内容:

class HomeViewController: UIViewController {
override viewDidLoad(){
super.viewDidLoad()
let goStoryboard = UIStoryboard(name: "Main", bundle: nil)
let walkthrough = goStoryboard.instantiateViewController(withIdentifier: "master") as! BWWalkthroughViewController
let page_one = goStoryboard.instantiateViewController(withIdentifier: "page1") as UIViewController
let page_two = goStoryboard.instantiateViewController(withIdentifier: "page2")as UIViewController
let page_three = goStoryboard.instantiateViewController(withIdentifier: "page3")as UIViewController

// Attach the pages to the master
walkthrough.delegate = self
walkthrough.add(viewController:page_one)
walkthrough.add(viewController:page_two)
walkthrough.add(viewController:page_three)

self.present(walkthrough, animated: true, completion: nil)
}
}

关于ios - 加载 LaunchScreen 后显示 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45514828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com