CurveGamma
CurveGamma

Reputation: 4559

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?

Upvotes: 0

Views: 224

Answers (1)

D.C.
D.C.

Reputation: 15588

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.

Upvotes: 2

Related Questions