2013-12-20 3 views
0

Я очень новичок в программировании в целом. Я пытаюсь обновить UILabel «Lives» с целым сроком жизни. Однако я продолжаю получать предупреждение «результат выражения не используется» в строкеПродолжайте получать результат выражения, не использованный при попытке обновления UILabel

Lives.text = @ "", life;

// 
// 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 
+1

В каком учебнике вы нашли синтаксис 'Lives.text = @" ", life;' ?? Взгляните на документацию NSString. (Spoiler: stringWithFormat.) –

+0

Я видел это после немного поискового запроса. Спасибо, что направили меня в нужное место! – tomanc

ответ

0

Если Lives является вашей меткой, тогда она должна быть такой, как показано ниже.

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

Большое вам спасибо! Должно быть, читал неправильный учебник! – tomanc

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

    } 
} 
Смежные вопросы