2010-09-30 102 views
1

我有一個file1.h file1.m file1.xib的廈門國際銀行有上有一個標籤,一個空白屏幕。我還有一個文件,做一些任意的計算和作爲計算循環將更新標籤。我應該在哪裏申報file1.h或*的UILabel值不計算該文件?放在哪裏聲明的目標C

謝謝帶動周邊。

回答

0

標籤應被宣佈爲在.h文件中的IBOutlet

​​

確保您在Interface Builder這個插座連接到您的標籤。

+0

它可能不會傷害也審查NIB對象的內存管理指引(https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmNibObjects.html#//apple_ref/doc/uid/TP40004998- SW2),以確保您的視圖控制器中內存不足的情況下,正確的行爲。 – 2010-09-30 23:00:33

1

該標籤應該聲明爲IBOutlet,因爲Josh在上述.h文件中說過,並且是在Interface Builder中連接您的標籤。

您還可以在.h文件中將您的標籤定義爲@property,並將其合成到.m文件中,以便您可以輕鬆地使用「myLabel」。運營商。

現在用你的計算更新標籤,只需在.h文件中定義updateLabel功能和編寫代碼,如下圖所示執行文件來實現更新:

 

@interface File1 { 
    IBOutlet UILabel *myLabel; 
} 

@property (nonatomic, retain) IBOutlet UILabel *myLabel; 

- (void)updateLabel:(id)sender; 

@end 
 

@implementation File1 
@synthesize myLabel; 

- (id)init { 
    if ((self = [super init])) { 
      // init custom work here 
    } 
    return self; 
} 

- (void)updateLabel:(id)sender { 

//Here sender can be any button who call this function or send it nil if not 

     //update your label here 
     myLabel.text = @"Updated Text"; 
     ...... 
} 

@end