• 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: custom NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: custom NSTextView


  • Subject: Re: custom NSTextView
  • From: "Parrish Myers" <email@hidden>
  • Date: Mon, 15 May 2006 20:11:49 -0700

Instead of 4 NSTextFields, I am tring to use one.  I'm tring to model
this after the NSDatePicker.  i.e.

                           -----------------------
Network Address:  | 127.  0.  0.  1 |
                           -----------------------

The idea is to have a single NSTextFiled that starts with a default IP
address, that can then be changed in a controled manor.  When the
NSTextFiled becomes the FirstResponder it will select the 1st of the
quad of numbers, '127'.  This allows the first quad to be modified.
If a tab or a right arrow key is pressed the second quad is selected,
and so on.  The space between the numbers is maintained and the '.'
characters are fixed and stationary.  Each number set is positive and
less than or equal to 255.

If I understand correctly, I either have to subclass NSTextView and
replace the field editor for the NSTextField with my subclass... or I
need to subclass the NSTextField and become the delegate of the field
editor.  Is this a correct assumption?  I have taken the first route
(modeling it after DTCPathView: some sample code I found on the net).
The problem occurs with my inability to change the selection of the
NSTextField after the control becomes FirstResponder... it selects the
whole field.  If I follow your instructions, I am still confused about
where to place that line of code... in the Controller that has a
reference to the NSTextField, or inside the field editor which is my
subclass of NSTextField.

BTW, thanks for your help.

On 5/14/06, Andrew Bowman <email@hidden> wrote:
Depends on how you're working with this.  Let me first see if I
understand what you're trying to do:

You want 4 separate NSTextFields, with dots between each.  The fields
should only allow non-negative integer entry.  You want to be able to
begin typing in one, and when you are about to enter the fourth
number, the next field should be selected, its contents cleared, and
the "fourth" number you just typed made into the first number of this
next textfield.

If this is the case (I know I'm making a lot of assumptions here),
you don't need to subclass the field editor, and I can provide some
code to help you out.

If I'm way off, give me some more info on what you're trying to do
and I'll take a look.

- Andrew Bowman


On May 14, 2006, at 2:54 PM, Parrish Myers wrote:

> Thank you for the response.  I'm still a bit confused though...  is
> this inside the NSTextView instance (that is the field editor) or
> outside in a NSTextField subclass?  Either way, which function or
> delegate is the correct place to put this?
>
> Thank you.
>
> On 5/14/06, Andrew Bowman <email@hidden> wrote:
>>
>>
>>
>> On May 14, 2006, at 9:39 AM, Parrish Myers wrote:
>>
>> Hello all,
>>
>> Just for fun, I thought I would try to implement an IP Address
>> Text Field
>> entry.  Remember the IP text entry widget in windows...  So the
>> idea is to
>> have 4 fields separated by '.' and only allow text selection
>> inside each
>> field.
>>
>>
>> From what I understand this is a good reason to subclass
>> NSTextView and swap
>> out the  FieldEditor for the  NTTextField when asked.  I'm getting
>> the hand
>> of things, but I can't seem to figure out one thing...
>>
>> Much like the NSDatePicker, I want to modify the  text selection
>> when the
>> widget  reacts to becomeFirstResponder.  But is seems that
>> NSTextFields
>> select all text when they become First Responder.  Can I change
>> that?  The
>> NSDatePicker does it somehow... does any one know how to change that?
>>
>> Thanks.
>> Parrish
>>
>>
>>
>> You're going to need to grab the field editor and make a
>> setSelectedRange
>> call with an empty range starting at the end of the text.  After
>> you've
>> obtained the field editor, it's something like this:
>>
>>       [fieldEditor setSelectedRange: NSMakeRange([[self stringValue]
>> length], 0)];
>>
>> - Andrew Bowman
>>


_______________________________________________
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: 
 >custom NSTextView (From: "Parrish Myers" <email@hidden>)
 >Re: custom NSTextView (From: Andrew Bowman <email@hidden>)
 >Re: custom NSTextView (From: "Parrish Myers" <email@hidden>)

  • Prev by Date: incompatible pointer type warning, but everything OK?
  • Next by Date: Do I need to release static "class" variables?
  • Previous by thread: Re: custom NSTextView
  • Next by thread: Adding objects to NSArrayController bound to Core Data
  • Index(es):
    • Date
    • Thread