• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: creating NSTextField instances
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: creating NSTextField instances


  • Subject: Re: creating NSTextField instances
  • From: Aaron Fothergill <email@hidden>
  • Date: Wed, 20 Oct 2004 01:40:00 +0100

Thanks! (on both counts, although the extra retain was a last ditch, "just in case I'm not retaining it" check. honest ;) )

Aaron
_____________________________
Aaron Fothergill : MD / Lead Coder
Strange Flavour Ltd
email@hidden
http://www.strangeflavour.com
On 20 Oct 2004, at 01:34, Clark Cox wrote:

On Wed, 20 Oct 2004 01:25:14 +0100, Aaron Fothergill <email@hidden> wrote:
I'd like to be able to create and display an NSTextField
programatically (rather than linking to a pre-made one from IB). I've
had a go at making one appear in the drawRect of the view I want it to
appear in by doing...

tempTextField = [[[NSTextField alloc] initWithFrame:tr] retain];
[tempTextField setEditable:YES];
[tempTextField setSelectable:YES];
[tempTextField setStringValue:[tempObject objectName]];
[tempTextField setBackgroundColor:[NSColor whiteColor]];
[tempTextField setDrawsBackground:YES];
[tempTextField setBordered:YES];
[tempTextField setNeedsDisplay:YES];

but nothing displays. kind of indicating I'm doing something wrong.

I haven't been able to find any examples where someone's
programatically creating a text field. They all seem to use the
Interface Builder route. Does anyone know if it's possible and if so,

Of course it's possible (i.e. there's nothing magic about IB; anything
it can do, you can do in code).

what am I doing wrong ?

You're not adding the textfield to any view or window. In order for a
view to be displayed, it must be in the view hierarchy of a visible
window. For example, if you have a pointer to the window in which you
want the text field to reside, you can do this:

[[myWindow contentView] addSubview: tempTextField];

(Also, BTW, you're retaining that text field too many times. When you
create it via -alloc, it is already implicitly retained once, and you
are retaining it a second time)



--
Clark S. Cox III
email@hidden
http://www.livejournal.com/users/clarkcox3/
http://homepage.mac.com/clarkcox3/


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >creating NSTextField instances (From: Aaron Fothergill <email@hidden>)
 >Re: creating NSTextField instances (From: Clark Cox <email@hidden>)

  • Prev by Date: Re: creating NSTextField instances
  • Next by Date: Re: Highlighting Drag Target
  • Previous by thread: Re: creating NSTextField instances
  • Next by thread: Re: creating NSTextField instances
  • Index(es):
    • Date
    • Thread