【问题标题】:How to access a IBAction from a SKView?如何从 SKView 访问 IBAction?
【发布时间】:2014-04-04 10:06:09
【问题描述】:

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

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)出现时,我希望它自动“排序”或“呈现”回 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'

...我尝试过的其他东西并没有让我有所收获。

欢迎任何想法或解决方案。如果你知道我做错了什么,或者如果整个方法有问题,我对 cme​​ts/critics 持开放态度。谢谢你:)。

【问题讨论】:

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


    【解决方案1】:

    我假设您使用 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];
    

    希望这会有所帮助,如果您有任何不清楚的地方,请随时询问。

    【讨论】:

      【解决方案2】:

      找到解决方案:

      在我的:

      @implementation MiniGameConcept
      

      这是SKScene 我将以下代码行放在我需要结束游戏的计时器/计数器的位置:

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

      这将我带到 1. VC,这是我的主屏幕,玩家可以在其中选择迷你游戏集。

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

      【讨论】:

        猜你喜欢
        • 2018-08-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多