2014-12-03 73 views
-1

我的代碼無法正常工作,因爲它無法識別「text」屬性。我正在使用ObjectiveC 我已經雙重檢查了所有內容,並且找不到錯誤。我是編程初學者,所以請原諒我的錯誤。 幫助非常需要! 我想爲我的應用程序創建一個計時器。Xcode:property「text」not found

int timeTick = 0; 

- (void)viewDidLoad { 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

- (IBAction)startTimer:(id)sender { 
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(tick) userInfo:nil repeats:YES]; 
} 

-(void)tick{ 
timeTick++; 
NSString *timeString = [[NSString alloc] initWithFormat:@"%d", timeTick]; 
labelTime.text = timeString; 

} 
@end 
+5

是什麼類型labelTime? – RobCroll 2014-12-03 02:09:21

+1

你應該發佈確切的錯誤 – Andy 2014-12-03 02:18:54

+0

這將有助於知道如何宣佈事情。 – 2014-12-03 02:34:20

回答

0

它不應該是:

self.labelTime.text = timeString; 

?否則,我看不到原因不起作用。

0

當你聲明一個屬性時,編譯器會聲明一個getter方法和一個setter方法(除非它是隻讀的)。要爲其方法創建實例變量和實現,您必須對其進行綜合。

通過增加綜合您的財產下列您.m文件的頂部: @synthesize labelTime = _labelTime;

它說:創建一個名爲labelTimesetLabelTime方法:即備份這些方法的實例變量應該是_labelTime

然後,在你的代碼,添加:

self.labelTime.text = timeString;