2015-05-22 130 views
1

首先,我必須說,這個平臺上有太多的信息,因爲每個人都在幫助。非常感謝你。Swift iOS:從ViewController中的實例執行Segue到另一個ViewController

目前,我已經到了一個地步,我無法自己走得更遠。

這是我的問題:

我有一個MainScreen的ViewController這是在導航控制器內嵌。 在這個MainScreen中,我可以用一個Segue創建一個GameViewController來創建一個Gamescene。 在這個Gamescene中,我有一個按鈕,當它被點擊時,顯示一個Popup並暫停Gamescene。

此彈出包含兩個按鈕:

  1. A鍵恢復比賽,並在彈出的消失。
  2. 一個應該結束Gamescene並返回到主屏幕的按鈕。

這是我的問題。 我無法爲結束按鈕創建功能。我嘗試過不同的星座,但它並沒有結束。

我認爲這裏的難點在於,這個按鈕是在一個單獨的類中。據我瞭解,這裏的層次結構是:

GameViewController - > GameScene - > Popup - > EndButton。

你有什麼想法可以解決這個問題嗎?有沒有其他方法可以解決這個過渡而不使用segues?

非常感謝您的幫助提前!

親切的問候, 菲爾

更新:

在我Gamescene彈出基本上是這樣的:

class GameScene: SKScene, SKPhysicsContactDelegate { 

    // .... 
    var pauseButton : UIButton! = UIButton() 
    var pausePopup : PausePopup! // my Popup class with the End button 
    // .... 

    override func didMoveToView(view: SKView) { 

    //configuring the button 
    pause_button.addTarget(self, action: "pauseButtonPressed", forControlEvents: UIControlEvents.TouchUpInside) 

    self.view?.addSubview(pause_button) 

    } 

    func pauseButtonPressed() { 
    self.pausePopup = PausePopup(nibName: "uxPausePopup", bundle: nil) 
    self.scene!.view!.paused = true 
    self.pausePopup.showInView(self.viewPlaceHolder, animated: true, scene: self) 
    } 
    // this is where my popup appears. 

在我的彈出窗口類我對EndButton一個行動,這位於Popup上,我想從中返回到主屏幕:

@IBAction func showMainScreen(sender: AnyObject) { 
    // this does not work ... 
    self.performSegueWithIdentifier("showMainScreen", sender: nil) 
} 
+0

嗨菲爾。你能否提供更多關於你所顯示的「Popup」的信息,比如你用來顯示它的代碼? – justinpawela

+0

嗨。我只是更新了一些信息。如果您需要更多信息,請告訴我。 –

回答

1

您不能從showInView調用其他視圖,您需要關閉popOver並從GameScene調用mainView,爲此您可以在PausePopup或協議中創建競爭處理程序,以將popOver的結果傳遞給GameScene處理結果

+1

嗨IcaroNZ,非常感謝您的回答。我設法使用協議達到我的目標。這確實是解決這個問題的一個非常簡單的方法。親切的問候 –

+0

@Phil_G,酷我很高興聽到我可以幫助 – Icaro

相關問題