2011-03-24 4 views
1

저는 학생 예산 신청서를 작성 중입니다. 그리고, 사용자가 새로운 경비를 추가했을 경우, 모든 경비의 액을 나타내는 라벨이 갱신해야 합니다만, 그렇지 않습니다. debuger 에서업데이트 UILabel, NSNumber에서 가치를 얻으십시오

float currentValue = [self.total floatValue]; 
self.total = [NSNumber numberWithFloat:(currentValue + amountValue)]; 
self.label.text = [NSString stringWithFormat:@"Razem: %@", total]; 

는 적절한 값을 가진다. 물론

나는이

self.label.text = [NSString stringWithFormat:@"something different"]; 

라벨과 같은 자신의 컨텐츠를 변경 입력 할 때.

EDIT.

내가 변경 한 코드 :

self.label.text = [NSString stringWithFormat:@"Razem: %@", [total stringValue]]; 

하지만 한 번만 업데이트합니다. 그래서, 당신이 부동 (또는 이중)를 인쇄하려면 YT

답변

7

코드에서 확인해야하는 유일한 변화와 '총' '[총 stringValue]를'교체하는 것입니다.

self.label.text = [NSString stringWithFormat:@"Razem: %@", [total stringValue]]; 

또는 라벨의 텍스트를 설정하여보십시오

[self.label setText:[NSString stringWithFormat:@"Razem: %@", [total stringValue]]]; 
+0

편집 할 수 있습니다. 코드를 변경했습니다 : \t self.label.text = [NSString stringWithFormat : @ "Razem : % @", [total stringValue]]; 하지만 한 번만 업데이트됩니다. 나는이 기록했습니다 [YT]을 [1] [1] : http://www.youtube.com/watch?v=tEr347-V6WU – milijkovic

+0

편집 내 answer.try이 저에게 결과를 알려줍니다. – iPhoneDev

+0

도움이되지 않습니다. 같은 결과 – milijkovic

2

당신이

self.label.text = [NSString stringWithFormat:@"Razem: %f", [self.total floatValue]]; 
1

NSNumber 객체이다 "% f를"이 아닌 "%의 @"를 사용한다 : 나는이 녹음 한 %@의 설명이 인쇄됩니다. float 값을 인쇄하려면 floatValue%f을 사용하십시오.

self.label.text = [NSString stringWithFormat:@"Razem: %f", [total floatValue]];