Creating a NSTextField

  • Hello,

    I am building Cocoa apps without the interface builder. Creating a
    NSWindow instance is really easy, and I can do:

        NSWindow* MainWindow = [[NSWindow alloc] initWithContentRect: MainWindowRect
          styleMask: NSTitledWindowMask | NSClosableWindowMask |
    NSMiniaturizableWindowMask | NSResizableWindowMask
            backing: NSBackingStoreBuffered
              defer: NO];

    But there is no initialization method for a NSTextField. How can I
    create a NSTextField? Just alloc?

    thanks,
    --
    Felipe Monteiro de Carvalho
  • On Feb 26, 2008, at 9:13 AM, Felipe Monteiro de Carvalho wrote:

    > But there is no initialization method for a NSTextField. How can I
    > create a NSTextField? Just alloc?

    Generally more like:

    [[NSTextField alloc] initWithFrame:someRect];

    Ken

    --
    Ken Worley
    Software Engineer, Tiberius, Inc.
  • On 2008 Feb, 26, at 8:13, Felipe Monteiro de Carvalho wrote:

    > But there is no initialization method for a NSTextField. How can I
    > create a NSTextField? Just alloc?

    NSTextField is a subclass of NSControl.  Use [[NSTextView alloc] -
    initWithFrame:].

    Then use -addSubview: on your window's -contentView.  And since your
    NSTextView is not instantiated in Interface Builder, keep it in an
    instance variable or something.
  • >> But there is no initialization method for a
    >> NSTextField. How can I
    >> create a NSTextField? Just alloc?
    > NSTextField is a subclass of NSControl. Use
    > [[NSTextView >alloc] - initWithFrame:]. Then use
    > -addSubview: on your window's -contentView. And
    since
    > your NSTextView is not instantiated in Interface
    > Builder, keep it in an instance variable or
    something.

    And don't forget to -release it after you add it to
    superview, since the latter retains it.

          Looking for the perfect gift? Give the gift of Flickr!

    http://www.flickr.com/gift/
previous month february 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29    
Go to today
MindNode
MindNode offered a free license !