【问题标题】:Enters the method but does not display anything进入方法但不显示任何内容
【发布时间】:2013-08-05 22:54:07
【问题描述】:

我正在尝试从 AppDelegate 调用 ViewController 类的方法,它进入该方法,但问题是没有显示任何内容,我一直在寻找,但找不到答案。有人可以帮助我吗?谢谢

这是代码:

AppDelegate.m

- (void)applicationWillEnterForeground:(UIApplication *)application
{

    if (mainDelegate.isflagON=TRUE)
    {

        ViewController *vc=[ViewController new];
        [vc pause];

    }

}

ViewController.m

- (void)viewDidLoad
{

    [super viewDidLoad];
    AppDelegate *mainDelegate = [[UIApplication sharedApplication] delegate];
    if (mainDelegate.isflagON==false)
    {
        mainDelegate.isflagON=true;
        CGSize viewSize = self.view.bounds.size;
        // Add this line

        GameScene *scene = [[GameScene alloc] initWithSize:viewSize];
        scene.scaleMode = SKSceneScaleModeAspectFill;
        self.scene = scene;

        // Configure the view.
        skView = (SKView *)self.view;
        skView.showsFPS = YES;
        skView.showsNodeCount = YES;


        // Present the scene.
        [skView presentScene:scene];

    }else
    {
        [self doPause];
    }
}

-(void) imprime
{
    [self doPause];

}

- (void)doPause {

    CGRect myImageRect = CGRectMake(0.0f, 0.0f, 200.0f, 200.0f);
    backImageView = [[UIImageView alloc] initWithFrame:myImageRect];
    [backImageView setImage:[UIImage imageNamed:@"dialogBox.png"]];
    [self.view addSubview:backImageView];
    [self.view sendSubviewToBack:backImageView];

    //set the position of the button

    buttonContinuar = [UIButton buttonWithType:UIButtonTypeCustom];

    [buttonContinuar setBackgroundImage:[UIImage imageNamed:@"dialogButton.png"]
                               forState:UIControlStateNormal];
    buttonContinuar.frame = CGRectMake(40.0f, 50.0f, 120, 35);
    [buttonContinuar addTarget:self action:@selector(buttonWasClicked:) forControlEvents:UIControlEventTouchUpInside];
    [buttonContinuar setTitle:@"Continuar" forState:UIControlStateNormal];
    //add the button to the view
    [self.view addSubview:buttonContinuar];

    buttonMapa = [UIButton buttonWithType:UIButtonTypeCustom];
    //[button setTitle:@"Continuar" forState:UIControlStateNormal];

    [buttonMapa setBackgroundImage:[UIImage imageNamed:@"dialogButton.png"]
                          forState:UIControlStateNormal];
    buttonMapa.frame = CGRectMake(40.0f, 85.0f, 120, 35);
    [buttonMapa addTarget:self action:@selector(buttonMapaClicked:) forControlEvents:UIControlEventTouchUpInside];
    [buttonMapa setTitle:@"Mapa" forState:UIControlStateNormal];
    //add the button to the view
    [self.view addSubview:buttonMapa];

    buttonMenu = [UIButton buttonWithType:UIButtonTypeCustom];
    //[button setTitle:@"Continuar" forState:UIControlStateNormal];

    [buttonMenu setBackgroundImage:[UIImage imageNamed:@"dialogButton.png"]
                          forState:UIControlStateNormal];
    buttonMenu.frame = CGRectMake(40.0f, 120.0f, 120, 35);
    [buttonMenu addTarget:self action:@selector(buttonMenuClicked:) forControlEvents:UIControlEventTouchUpInside];
    [buttonMenu setTitle:@"Menu" forState:UIControlStateNormal];
    //add the button to the view
    [self.view addSubview:buttonMenu];

}

【问题讨论】:

  • 您的代码格式混乱,所以我没有深入了解它,但我可以告诉您第一行包含错误。当您应该使用相等运算符时,您正在使用赋值运算符。换句话说if (mainDelegate.isflagON = TRUE)应该是if (mainDelegate.isflagON == TRUE)
  • 另外,在 Objective-C 中你应该使用 YES/NO 而不是 TRUE/FALSE
  • 在第二行你不应该做“ViewController *vc=[ViewController new]”,而是做[[ViewController alloc] init]。

标签: methods call viewcontroller appdelegate


【解决方案1】:

你可以试试这个

- (void)applicationWillEnterForeground:(UIApplication *)application
{

    if (mainDelegate.isflagON=TRUE)
    {

        ViewController *vc=[[ViewController alloc]init];
        [vc pause];

    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多