Re: multiline NSTextFields
Re: multiline NSTextFields
- Subject: Re: multiline NSTextFields
- From: Brian Webster <email@hidden>
- Date: Mon, 24 Sep 2001 12:46:14 -0500
On Monday, September 24, 2001, at 08:47 AM, cocoa-dev-
email@hidden wrote:
Apple's Network Setup features three special NSTextFields (DNS, search
domains, proxy bypass addresses) which allow multiple lines by pressing
return instead of the regular (non-intuitive) opt-return. How
is it done?
I've looked into the nib, but no magic is revealed here. No
subclass, no
formatter, only the delegate is set. In IB test mode it doesn't work
properly.
This should be done through a custom field editor. Every window
has a field editor, which is an instance of NSText, allocated by
default. When you click on an NSTextField to perform editing,
the text system sets the frame of the field editor to lay right
where the text field is and inserts it into the view hierarchy.
This is done so that you don't have the overhead of a separate
NSText object for every text field in your app.
To override the custom field editor, you should implement the
windowWillReturnFieldEditor:toObject: method in your window's
delegate. If the object passed in as the second argument is one
of the text fields you want to use the custom editor, return
your custom one, otherwise return nil. To create the custom
editor, just allocate an instance of NSTextView and set it the
message [myTextView setFieldEditor:NO]. This will cause it to
act like a "normal" text view, i.e. it will not end editing on
return/enter.
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster