【问题标题】:Call Method from Another Class Not Working - iOS来自另一个类的调用方法不起作用 - iOS
【发布时间】:2014-09-11 00:13:24
【问题描述】:

我的“GameScene.m”类 (SKScene) 中有这个:

GameViewController * game = [[GameViewController alloc] init];
[game imgMethod];

我的“GameViewController.m”(UIViewController)中有这个方法:

- (void)imgMethod{
    NSLog(@"test");
    img.alpha = 0.5;
}

问题是“测试”已打印出来,但 img.alpha = 0.5 不起作用。我已确保图像通过情节提要链接,并且该行在 viewDidLoad 方法中有效,但我需要从我的 GameScene 类中调用它。有什么办法吗?

【问题讨论】:

    标签: ios iphone uiviewcontroller sprite-kit skscene


    【解决方案1】:

    “test”打印出来了,但是img.alpha = 0.5不起作用

    这将在两种情况下发生。

    1. 为现有对象分配新内存时 (GameViewController)

    2. 当您忘记从SKScene 类分配GameViewController img 属性时(在GameViewController 分配之后)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-12
      • 2019-03-20
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      • 2015-07-19
      • 2021-09-25
      相关资源
      最近更新 更多