2013-08-05 31 views
0

我想調用一個方法來ViewController類窗體AppDelegate,它進入該方法,但問題是,不顯示任何東西,我正在尋找,但我找不到答案。有人可以幫助我嗎?感謝輸入方法,但不顯示任何

這是代碼:

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

} 
+0

你的代碼是一個巨大的格式化混亂,所以我沒有得到f進入它,但我可以告訴你,第一行包含一個錯誤。當您使用相等運算符時,您正在使用賦值運算符。換句話說'if(mainDelegate.isflagON = TRUE)'應該是'if(mainDelegate.isflagON == TRUE)' – davidf2281

+0

另外,在Objective-C中,你應該使用YES/NO而不是TRUE/FALSE – davidf2281

+0

而在第二行你不應該做「ViewController * vc = [ViewController new]」,而是做[[ViewController alloc] init]。 – onnoweb

回答

0

你可以試試這個

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

    if (mainDelegate.isflagON=TRUE) 
    { 

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

    } 

} 
+0

謝謝,但它仍然無法正常工作..... – Effectoxx