2012-11-03 54 views
1

我有一个“本地声明隐藏实例变量”错误的“secondsLeft”和“未使用的变量”小时,分钟和秒。预先感谢您提供的任何帮助。本地声明隐藏实例变量/未使用的变量警告

.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

您必须调用自变量。例如:

self.hours = self.secondsLeft/3600; 

此外,如果你想声明具有相同名称稍后变量,可以使用其他名称,例如:

int hours_tmp; 
1

摆脱从“viewDidLoad”功能,这些行:

int hours, minutes, seconds; 
int secondsLeft; 

这两条线正是产生你看到的“local declaration hides instance variable”错误。

就像edzio说的,在你引用的任何属性前面使用“self.”。 +1给他!

+0

声明感谢了很多答复我的问题的快速响应 - 错误信息都没有了! – user1796454

0

“属地申报隐藏实例变量”错误“secondsLeft”

你在.m文件在此行secondsLeft = 16925;编译器在局部变量-(void)viewDidLoad方法存储16925,而不是重新声明int secondsLeft;

所以的这是在.h文件中

您应该删除的 int hours, minutes, seconds; int secondsLeft;的重声明中.m文件中声明int secondsLeft;。或者,您可以使用其他变量名称

“未使用的变量”小时,分钟和秒钟。 嗯,这只是一个警告,强调你从来没有使用这些变量int hours, minutes, seconds;这是-(void)viewDidLoad方法

相关问题