2012-03-28 5 views
0

메인 윈도우로 돌아 왔을 때 앱의 값을 어떻게 재설정 할 수 있습니까? 나는 여러 가지 뷰를 가지고 있는데, 마지막 창은 타이머와 2 개의 카운터를 포함하고있다. 앱을 처음 실행하면 처음 창으로 돌아가서 동일한 창을 따라 최종 창으로 간다. , 처음에는 여전히 가치가 있습니다. 내가 무엇을 할 수 있을지? 나의 첫 번째 창에 와서 오픈 처음처럼 응용 프로그램을 다시 설정하는 방법이 있습니다viewcontroller의 값을 어떻게 재설정 할 수 있습니까?

`enter code here` 
    // Created by MiniMac on 3/26/12. 
    // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 
    // 

    #import "juegoAB.h" 
    #import "SwitchViewController.h" 

    @implementation juegoAB 
    @synthesize cronometro, button, Rounds; 

     int y = 0; 

     - (IBAction)buttonPressed: (id) sender { 
      y++; 
      if (y>10) y=10; 
       [self updateText]; 
     } 

     - (void)updateText { 
      switch (y) { 
       case 0: [Rounds setText:@"5."]; break; 
       case 1: [Rounds setText:@"5."]; break; 
       case 2: [Rounds setText:@"4."]; break; 
       case 3: [Rounds setText:@"4."]; break; 
       case 4: [Rounds setText:@"3."]; break; 
       case 5: [Rounds setText:@"3."]; break; 
       case 6: [Rounds setText:@"2."]; break; 
       case 7: [Rounds setText:@"2."]; break; 
       case 8: [Rounds setText:@"1."]; break; 
       case 9: [Rounds setText:@"1."]; break; 
       case 10: [Rounds setText:@"0."]; break; 
       default: break; 
      } 
     } 

     NSTimer *timer; int i; 

     -(IBAction)playsound { 
      NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:        
      @"%@/disparo04.WAV",[[NSBundle mainBundle] resourcePath]]];                      

      NSError *error; 
      audioplayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error]; 
      audioplayer.numberOfLoops = 0; 
      if(audioplayer == nil) NSLog(@"%@",[error description]); 
      else [audioplayer play]; 
     } 

     -(IBAction)pressButton { 
      i = 11; 
      timer = [NSTimer scheduledTimerWithTimeInterval:1 
                target:self 
               selector:@selector(timerFires) 
               userInfo:nil 
                repeats:YES]; 
      [timer fire]; 
     } 

     - (void) timerFires{ 
      if(i > 0) { 
       i--; 
       cronometro.text = [NSString stringWithFormat:@"%i", i]; 
      } else { 
       cronometro.text = @"TIEMPO!!"; 
       timer = nil; 
      } 
     } 

     - (IBAction)onStopPressed: (id)sender { 
      [timer invalidate]; 
      timer = nil; 
     } 

     -(IBAction)generateNumbers { 
      int randomNumber = rand() % 26; 
      switch (randomNumber) { 
       case 0: 
        label.text = @"A"; 
        label1.text = @"Z"; 
        label2.text = @"Q"; 
        break; 
       case 1: 
        label.text = @"B"; 
        label1.text = @"Y"; 
        label2.text = @"W"; 
        break; 

     -(IBAction)plus { 
      counter=counter + 1; 
      count.text = [NSString stringWithFormat:@"%i",counter]; 
     } 

     -(IBAction)zero { 
      counter=counter - 1; 
      count.text = [NSString stringWithFormat:@"%i",counter]; 
     } 

     -(IBAction)plus2 { 
      counter2=counter2 + 1; 
      count2.text = [NSString stringWithFormat:@"%i",counter2]; 
     } 

     -(IBAction)zero2 { 
      counter2=counter2 - 1; 
      count2.text = [NSString stringWithFormat:@"%i",counter2]; 
     } 

     - (void)viewWillAppearBOOL)animated { 
      [super viewWillAppear:animated]; 
     } 

     - (id)initWithNibName:(NSString *)nibNameOrNil 
      bundleNSBundle:(NSString *)nibBundleOrNil {                       
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
      if (self) { 
       // Custom initialization 
      } 
      return self; 
     } 

     - (IBAction)goBack { 
      SwitchViewController *second = [[SwitchViewController alloc]  
              initWithNibName:nil bundle:nil]; 
      [self presentModalViewController:second animated:YES]; 
      [second release]; 
     } 

     - (void)dealloc { 
      [cronometro release]; 
      [button release]; 
      [Rounds release]; 
      [super dealloc]; 
     } 

     - (void)didReceiveMemoryWarning { 
      // Releases the view if it doesn't have a superview. 
      [super didReceiveMemoryWarning]; 

      // Release any cached data, images, etc that aren't in use. 
     } 

     #pragma mark - View lifecycle 

     - (void)viewDidLoad{ 
      [super viewDidLoad]; 
      // Do any additional setup after loading the view from its nib. 
     } 

     - (void)viewDidUnload { 
      [super viewDidUnload]; 
      // Release any retained subviews of the main view. 
      // e.g. self.myOutlet = nil; 
     } 

     - (BOOL)shouldAutorotateToInterfaceOrientationUIInterfaceOrientation)interfaceOrientation {       
      // Return YES for supported orientations 
      return (interfaceOrientation == UIInterfaceOrientationPortrait); 
     } 

     - (void)resetToOriginalState: (id)sender { 
      //Do your stuff here 
     } 

     @end 

:

코드 (마지막 창)입니다.

아무도 도와 줄 수 있기를 바랍니다. 고맙습니다.

답변

0

당신의 viewWillAppear이 당신의 가치를 (이런 일이

- (void)viewWillAppearBOOL)animated {. 
     [super viewWillAppear:animated]; 
     counter = 0; 
     counter2 = 0; 
     timer = 0; 
    } 
을 :) 다시 변경
관련 문제