2014-04-04 50 views
0

我正在製作一款小遊戲,少數迷你遊戲。在1.VC上我有一個scrollView裏面的UIButton來選擇迷你遊戲。當miniGame被加載(一個UIVC)時,它會加載一個帶有所選SKScene遊戲的SKView。
這是我的應用程序的查看設置:如何從SKView訪問IBAction?

1. 
    UIViewController -> 1.1. ScrollView -> 1.1.1. UIButton -> 1.1.1.1. UIViewController -> 1.1.1.1.1. SKView -> 1.1.1.1.1.1. SKScene (the 1. mini game). 
    In the 1.1.1.1. VC I have a backButton (UIButton) which returns me back to the 1.VC. 
    Since I added the backButton in 1.1.1.1.VC I can always return at any moment in the first mini game to 1.VC. 

問題: 從1.1.1.1回去的唯一方法。 (或更深)到1是通過單擊UIButton。我想以編程方式回去。當呈現endGameVC(SKScene)時,我希望它自動地「seque」或「呈現」回1.VC(使用NSTimer)。

到目前爲止,我曾嘗試:

1.

[self.view removeFromSuperview]; 

結果: 黑屏 - 不能做任何事情,從這裏

2.

[self.view presentScene:nil]; 

結果:灰色屏幕 - 我刪除了skview,並可以返回按鈕點擊

3.

[self.view removeFromSuperview]; 
[self.view addSubview:[[WBMGamesDataManager sharedInstance] tempy]]; 

結果:

-[WBMMainVC superview]: unrecognized selector sent to instance 0x9ac4c30 
2014-04-04 11:54:06.317 KinderApp[1940:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WBMMainVC superview]: unrecognized selector sent to instance 0x9ac4c30' 

...我試過沒有得到任何地方我其他的東西。

歡迎任何想法或解決方案。如果你知道我做錯了什麼,或者如果整個方法很腥,我都會接受評論/批評。謝謝 :)。

回答

0

找到了解決方案:

在我:

@implementation MiniGameConcept 

其是SKScene我已經把下面的代碼行,在其中,我用的定時器/計數器,其中我所需要的遊戲的地方結束:

[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil]; 

這導致我1. VC是我的主屏幕,玩家可以選擇迷你遊戲集。

它爲我工作。我還找到了一種退後一步的方法,但這基本上讓我接觸到rootVC。使用NSLog的控制檯輸出顯示VC名稱。

0

我假設你正在使用這樣的方式塞格斯是通過彈出當前視圖控制器

[self.navigationController popViewControllerAnimated:YES]; 

但對於這個工作,你需要從託管SKView所以視的UIViewController叫它你需要回去編程,傳遞的UIViewController到所需視圖的引用,並創建一個將簡單地調用上面一行

/////in UIViewController 
-(void)popIt{ 
     [self.navigationController popViewControllerAnimated:YES]; 
} 

////in the view where you want to simulate the back method 
[referenceToVC popIt]; 

希望這會有所幫助,隨意問一個方法,如果您有什麼不清楚。