2011-11-28 34 views
0

一直在研究單視圖遊戲,其中包括targetValue和score,它們都應該出現在視圖的出口中。將它們連接到IB中的視圖控制器(文件所有者),並使用targetValue出現,但現在,在添加一些代碼後,它不再出現。targetValue,分數不出現在視圖的店鋪中

怎麼了?

下面是從BullseyeViewController.m代碼:

#import "BullsEyeViewController.h" 

@implementation BullsEyeViewController { 
    int currentValue; 
    int targetValue; 
    int score; 
} 

@synthesize slider; 
@synthesize targetLabel; 
@synthesize scoreLabel; 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)updateLabels 
{ 
    self.targetLabel.text = [NSString stringWithFormat:@"%d", targetValue]; 
    self.scoreLabel.text = [NSString stringWithFormat:@"%d",score]; 
} 

- (void)startNewRound 
{ 
    targetValue = 1 + (arc4random() % 100); 
    currentValue = self.slider.value; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self startNewRound]; 

} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    self.slider = nil; 
    self.targetLabel = nil; 
    self.scoreLabel = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 

- (IBAction)showAlert 
{ 
    int difference = abs(targetValue - currentValue); 
    int points = 100 - difference; 
    score += points; 

    NSString *title; 
    if (difference == 0) { 
     title = @"Perfect!"; 
     points += 100; 
    } else if (difference < 5) { 
     if (difference == 1) { 
     points += 50; 
     } 
     title = @"You almost had it!"; 
    } else if (difference < 10) { 
     title = @"Pretty good!"; 
    } else { 
     title = @"Not even close..."; 
    } 


     NSString *message = [NSString stringWithFormat:@"You scored %d points", points]; 



    UIAlertView *alertView = [[UIAlertView alloc] 
          initWithTitle:title 
          message:message 
          delegate:self 
          cancelButtonTitle:@"OK" 
          otherButtonTitles: nil]; 

    [alertView show]; 


} 

- (IBAction)sliderMoved:(UISlider *)slider 
{ 
    currentValue = lroundf(slider.value); 
} 

@end 

回答

0

,如果你設置updateLabels斷點,它曾經打?

此外,改變你的updateLabels方法是這樣的:

- (void)updateLabels 
{ 
    targetLabel.text = [NSString stringWithFormat:@"%d", targetValue]; 
    scoreLabel.text = [NSString stringWithFormat:@"%d",score]; 
} 

你從你的視圖控制器之外指這些標籤?如果不是,他們是否需要成爲房產?