2017-08-04 71 views
0

我正在嘗試爲我的應用程序創建一個演練(介紹)。我正在使用BWWalkthrough來做到這一點。如果想在點擊一個按鈕後打開這個視圖控制器,它會起作用(正如你可以在下面的代碼中看到的那樣)。但我不想這樣做。我想在啓動屏幕加載後打開此視圖控制器。LaunchScreen加載後顯示ViewController

當我點擊主視圖的「初始視圖控制器」,並在viewDidLoad方法中添加了下面的代碼時,我只能看到母版頁,但看不到視圖控制器(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) 

} 
+0

我之前已經實現了這個..但它在OBJ-C ..還是想看看嗎? –

回答

0

首先,轉到您的主要故事板並創建一個新的視圖控制器。你還應該創建一個視圖控制器類。這將是您的主屏幕故事板,並且您將把它設置爲您的初始視圖控制器。

您先前創建的類,你可以把這個:

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

作爲初始視圖控制器的視圖控制器無法在其「viewDidLoad」方法中顯示其他視圖控制器。 – nathan

相關問題