目标c-如何正确地运行来自其他类的方法



我在第二类(SKView)中得到了代码:

 -(void)backToMenu
 {
     GamePlay1 *controller = [[GamePlay1 alloc]init];
     [controller end];
 }

在我的第一个类中,我有这样一个方法来消除视图控制器:

 -(void)end
 {
      NSLog(@"I am here");
      [self dismissViewControllerAnimated:YES completion:nil];
 }

它运行得很好,我收到了"我在这里"的信息。。但这不会触发解雇线吗?也许问题是我正在创建类GamePlay1的新实例,而不是调用已经存在的实例?我在这里迷路了,不知道该怎么办。

是的,您了解的实际问题

尝试创建

//在appdegate.h 中

GamePlay1 *controller;

//在appdegate.m 中

controller = [[GamePlay1 alloc]init];

app delegate文件中,以便您可以访问控制器对象。然后它将触发解除

要访问它,请使用

AppDelegate  *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate.controller end];

相关内容

最新更新