2010-09-30 104 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