开发者

Adding a label to the main view

I am trying to run the following code which I found on this site, 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

However, I get the error: 开发者_开发问答'view' is undefined. What am I doing wrong? do I have to link something up?


It depends where you are trying to do this. 'view' in this case is supposed to be an instance variable in the class where this code lives. You might want to post the entire file so we can take a look. Otherwise, make sure your class does in fact have an ivar named view, or is a subclass with a view member.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜