簡體   English   中英

Swift-如何編寫一個按鈕以進入mainScene,而沒有回退?

[英]Swift - How to program a button to go to the mainScene, without segues going back?

我正在制作一個游戲,當您按下開始按鈕時,它將帶您進入游戲場景 ,然后在游戲結束時,屏幕上會出現重播按鈕 ,當按下重播按鈕時,它將帶我進入主主屏幕不在我的游戲場景中。 經過幾個小時的瀏覽,我發現了一些與我想要的東西有關的東西,但這是在Objective-C中。 目標C的代碼如下,請迅速告訴我它的含義,因為我對目標C一點都不熟悉。

(IBAction)prepareForUnwind:(UIStoryboardSegue*)sender
{
    UIViewController *sourceViewController = sender.sourceViewController;

    // Pull any data from the view controller which initiated the unwind segue.
}

這是您的快速代碼:

@IBAction func prepareForUnwind(segue: UIStoryboardSegue) {
    let sourceViewController = sender.sourceViewController
}

除了@Dharmesh Kheni的答案

您還可以通過編程方式調用viewcontroller,而不會造成麻煩。

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("SomeID") as! UIViewController
self.presentViewController(vc, animated: true, completion: nil)

您可以為需要顯示的視圖控制器設置標識符,如下所示:

在此處輸入圖片說明

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM