Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios targetValue,分数不显示在视图的出口中_Ios_Xcode - Fatal编程技术网

Ios targetValue,分数不显示在视图的出口中

Ios targetValue,分数不显示在视图的出口中,ios,xcode,Ios,Xcode,一直致力于单视图游戏,其中包括targetValue和score,这两个都应该出现在视图中的outlets中。将它们连接到IB中的视图控制器文件的所有者,并且targetValue以前会显示,但现在,在添加一些代码后,它不再显示 怎么了 以下是BullseyeViewController.m中的代码: #import "BullsEyeViewController.h" @implementation BullsEyeViewController { int currentValue;

一直致力于单视图游戏,其中包括targetValue和score,这两个都应该出现在视图中的outlets中。将它们连接到IB中的视图控制器文件的所有者,并且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

如果在UpdateLabel上设置断点,它是否会命中

另外,将updateLabels方法更改为如下所示:

- (void)updateLabels
{
    targetLabel.text = [NSString stringWithFormat:@"%d", targetValue];
    scoreLabel.text = [NSString stringWithFormat:@"%d",score];
}
是否从视图控制器外部引用这些标签?如果不是,它们是否需要是属性