我正在尝试运行我在该网站上找到的以下代码,Sample code for creating a NSTextField "label"? :
#import "AppController.h"
@implementation AppController
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSTextField *textField;
textField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, 200, 17)];
[textField setStringValue:@"My Label"];
[textField setBezeled:NO];
[textField setDrawsBackground:NO];
[textField setEditable:NO];
[textField setSelectable:NO];
[view addSubview:textField];
}
@end
但是,我收到错误:“ View ”未定义。我究竟做错了什么?我必须链接一些东西吗?
最佳答案
这取决于您尝试在何处执行此操作。在这种情况下,“view”应该是该代码所在的类中的实例变量。您可能想发布整个文件,以便我们查看。否则,请确保您的类实际上有一个名为 view 的 ivar,或者是具有 View 成员的子类。
关于objective-c - 向主视图添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6339043/