ios - 加载 LaunchScreen 后显示 ViewController

标签 ios iphone swift xcode swift3

我正在尝试为我的应用程序创建一个演练(简介)。我正在使用 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/

相关文章:

swift - 如何在 swift 中修改 shell 环境变量?

swift - Realm Swift iOS7 文档

ios - ApplePay PKPaymentAuthorizationViewController 始终显示正在处理

iphone - 更改所有 UIView 的背景图像

iphone - 如何获取表中特定字段的最大值?

iphone - 通过应用程序打开配置文件

ios - 在swift中使变量值保持不变

ios - 信标和用户位置权限

ios - 无法从 SQLite 数据库获取数据以显示在 iOS 应用程序中

ios - 如何从 NSDate iOS 获取 UTC 时间