2012-11-03 1 views
1

시, 분 및 초에 대해 "secondsLeft"및 "unused variable"에 대해 "local declaration instances variables"오류가 있습니다. 이 웹 사이트에서 제공 할 수있는 도움에 대해 미리 감사드립니다.로컬 선언은 인스턴스 변수/사용하지 않는 변수 경고를 숨 깁니다.

.H 파일

#import <Foundation/Foundation.h> 
#import <UIKit/UIKit.h> 
#import "BT_viewController.h" 



@interface BT_screen_blank : BT_viewController { 

    NSTimer *timer; 
    IBOutlet UILabel *myCounterLabel; 
} 

@property (nonatomic, retain) UILabel *myCounterLabel; 
@property (nonatomic) int secondsLeft; 
@property (nonatomic) int minutes; 
@property (nonatomic) int hours; 
@property (nonatomic) int seconds; 

-(void)updateCounter:(NSTimer *)theTimer; 
-(void)countdownTimer; 

@end 

하는 .m 파일 당신은 자기와 변수를 호출해야

@implementation BT_screen_blank 
@synthesize myCounterLabel; 
@synthesize secondsLeft, hours, minutes, seconds; 


//viewDidLoad 
-(void)viewDidLoad{ 
[BT_debugger showIt:self:@"viewDidLoad"]; 
[super viewDidLoad]; 


int hours, minutes, seconds; 
int secondsLeft; 


secondsLeft = 16925; 
[self countdownTimer]; 
} 

- (void)updateCounter:(NSTimer *)theTimer { 
if(secondsLeft > 0){ 
    secondsLeft -- ; 
    hours = secondsLeft/3600; 
    minutes = (secondsLeft % 3600)/60; 
    seconds = (secondsLeft %3600) % 60; 
    myCounterLabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes,   seconds]; 
} 
else{ 
    secondsLeft = 16925; 
} 
} 

답변

1

이 "viewDidLoad"기능에서이 줄을 제거 : 또한, 같은 이름을 가진 나중에 변수를 선언 할 예를 들어, 다른 이름을 사용하는 경우

self.hours = self.secondsLeft/3600; 

:

예를 들어
int hours, minutes, seconds; 
int secondsLeft; 

이 두 줄은 현재보고있는 "local declaration hides instance variable"오류를 생성하는 것입니다.

및 edzio와 마찬가지로 참조하려는 속성 앞에 "self."을 사용하십시오. 그에게 +1!

+0

제 질문에 대한 답변을 많이 주셔서 감사합니다. 오류 메시지가 사라졌습니다! – user1796454

0

secondsLeft = 16925; 컴파일러가 대신 -(void)viewDidLoad 방법에 로컬 변수에 16925을 저장하는이 라인에

그래서하는 .m 파일에 int secondsLeft;을 재 선언

당신 "secondsLeft"에 대한 오류 "지역의 선언은 인스턴스 변수를 숨 깁니다" 당신은하는 .m 파일에 int hours, minutes, seconds; int secondsLeft;의 재 선언을 제거해야

.H 파일에 선언 int secondsLeft;의. 또는 다른 변수 이름

을 "시간, 분 및 초"로 사용할 수 있습니다. 글쎄,이 변수들을 사용하지 않는다는 것을 알리는 경고 일뿐입니다. -(void)viewDidLoad에서 선언 된