0

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?

Community
  • 1
  • 1
Ali
  • 4,311
  • 11
  • 44
  • 49

1 Answers1

2

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.

D.C.
  • 15,340
  • 19
  • 71
  • 102
  • I thought view referred to the main nib file/window. How do I get the label added to the main window? – Ali Jun 14 '11 at 13:58