尝试更新UILabel时,继续使用表达式结果

时间:2013-12-20 08:18:03

标签: ios objective-c xcode5.0.1

我对编程很新。我试图用整数生命来更新UILabel“Lives”。但是我继续在行

中收到警告“表达结果未使用”

Lives.text = @“”,生活;

//
//  Game.m
//  SprinklerDash

#import "Game.h"

@interface Game ()

@end

@implementation Game


-(void)Walk{
    Runner.animationImages = [NSArray arrayWithObjects:
                              [UIImage imageNamed:@"Runner1.png"],
                              [UIImage imageNamed:@"Runner2.png"],
                              [UIImage imageNamed:@"Runner3.png"],
                              [UIImage imageNamed:@"Runner4.png"],
                              [UIImage imageNamed:@"Runner5.png"],
                              [UIImage imageNamed:@"Runner6.png"],
                              [UIImage imageNamed:@"Runner7.png"],
                              [UIImage imageNamed:@"Runner8.png"], nil];

    [Runner setAnimationRepeatCount:INFINITY];
    Runner.animationDuration = .75;
    [Runner startAnimating];
}

-(void)Moving{
    Runner.center = CGPointMake(Runner.center.x, Runner.center.y - UpMovement);
    if(CGRectIntersectsRect(Runner.frame, Water.frame)){
        life = life - 1;
        Lives.text = @"",life;
        Runner.center = CGPointMake(Runner.center.x, Runner.center.y + 100);

    }
}

-(IBAction)StartGame:(id)sender{
    Start.hidden=YES;
    UpMovement = 3;
    [self Walk];
    Movement = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(Moving) userInfo:nil repeats:YES];
}




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

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

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

2 个答案:

答案 0 :(得分:0)

如果Lives是您的标签,那么它应该如下所示。

Lives.text =[NSString stringWithFormat:@"%@",life]; /// if life is string  
Lives.text =[NSString stringWithFormat:@"%d", life]; /// if life is integer

答案 1 :(得分:0)

用您的方法替换它,最好去。

-(void)Moving{
    Runner.center = CGPointMake(Runner.center.x, Runner.center.y - UpMovement);
    if(CGRectIntersectsRect(Runner.frame, Water.frame)){
        life = life - 1;
        lives.text = [NSString stringWithFormat:@"%d",life];
      //  Lives.text = @"",life;
        Runner.center = CGPointMake(Runner.center.x, Runner.center.y + 100);

    }
}