【发布时间】:2011-10-06 18:21:34
【问题描述】:
我无法以编程方式更改标签中的文本。
当我运行以下代码时,NSLog 确实显示“Setting myLabel to = Hello World!”,但屏幕上的标签没有改变。
UIViewOverlay *overlayWindow;
overlayWindow = [[[NSBundle mainBundle] loadNibNamed:@"UIViewOverlay" owner:self options:nil] objectAtIndex:0];
[self addSubview:overlayWindow];
[overlayWindow setMyLabel:@"Hello World!"];
我的 NIB 文件有一个 300x300 的窗口,带有一些标签和按钮。 有一个标签,它连接到插座中的 myLabel。 UIView 会显示,只是无法以编程方式更改文本。
UIViewOverlay.h
#import <UIKit/UIKit.h>
@interface UIViewOverlay : UIView {
IBOutlet UILabel *myLabel;
}
- (void)setMyLabel:(NSString *) label;
@end
UIViewOverlay.m
#import "UIViewOverlay.h"
@implementation UIViewOverlay
- (void)setMyLabel:(NSString *) label {
myLabel.text = label; // THIS LINE IS NOT WORKING! :-(
NSLog(@"Setting myLabel to = %@", label); // This line is working.
}
@end
提前谢谢..
【问题讨论】:
标签: cocoa-touch uiview loadnibnamed