如何从SKView访问IBAction?

时间:2014-04-04 10:06:09

标签: objective-c ios7 uiview uiviewcontroller sprite-kit

我正在用一些迷你游戏制作一款小游戏。在1.VC我在scrollView中有UIButtons来选择迷你游戏。当加载miniGame(一个UIVC)时,它会加载带有所选SKScene游戏的SKView 这是我的App视图设置:

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'

...我试过的其他东西并没有把我带到任何地方。

欢迎任何想法或解决方案。如果你知道我做错了什么,或者整个方法是多么可疑,我愿意接受评论/批评。谢谢你:)。

2 个答案:

答案 0 :(得分:0)

我假设你正在使用segues这样做是通过弹出当前视图控制器

[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];

希望这有帮助,随时可以询问您是否有任何不清楚的地方。

答案 1 :(得分:0)

找到解决方案:

在我的:

@implementation MiniGameConcept

这是一个SKScene我已将以下代码行放在我使用计时器/计数器的地方,我需要游戏结束:

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

这导致我进入1. VC,这是我的主屏幕,玩家可以选择迷你游戏。

它对我有用。我也找到了退步的方法,但这基本上让我进入了rootVC。使用NSLog的控制台输出显示VC名称。