2013-12-20 2 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.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); 

    } 
}