我有一个file1.h file1.m file1.xib xib有一个带有标签的空白屏幕。我有另一个文件进行任意计算,并将更新标签作为计算循环。我应该在file1.h或执行计算的文件中声明UILabel *值?
谢谢你开车。
答案 0 :(得分:1)
标签应该像Josh在上面的.h文件中所说的那样声明为IBOutlet,是的,在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
答案 1 :(得分:0)
标签应在.h文件中声明为IBOutlet
:
@interface File1 {
IBOutlet UILabel *mylabel;
}
@end
确保在Interface Builder中将此插座连接到您的标签。