• 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: NSStepper and NSTextField changes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSStepper and NSTextField changes


  • Subject: Re: NSStepper and NSTextField changes
  • From: Brian Webster <email@hidden>
  • Date: Thu, 12 Dec 2002 23:45:04 -0600

On Thursday, December 12, 2002, at 06:20 PM, email@hidden wrote:

In my app, I have close to a hundred NSTextField/NSStepper combos which
basically manage a bunch of number inputs.

I need to be notified when the text field changes, so I've set the delegate
of all these fields to handle controlTextDidChange. This works fantastic
when the user types in new numbers, and I can act appropriately.

However, if the text field does not have focus and the user clicks on the
stepper, I never get notified that the text field changes.

Is there a smooth way to solve this, or do I need to write a lot of code to
deal with each one of these steppers?

You don't say so specifically, but from the description it sounds like you have the steppers hooked up directly to the text fields via the takeObjectValue: action (or one of its variants, e.g. takeIntValue:), so I'm going to operate on that assumption here.

The controlTextDidChange: notification will send notifications as the user types in the text field. It does not post notifications when the object value of the is changed in the general case, through an action or a direct call to setObjectValue:. Also, when the user is editing in one of these fields, a notification will be set on every time a character is added or deleted. This may or may not be the behavior you want. If you only want to update when the user hits return or tabs out of the field, you should hook up the text field's action to your controller instead of using the delegate method.

The usual set up for a text field/stepper combination is to store the values in your controller and hook up the text field and stepper to send their action messages to the controller object. The value is then updated in the controller according to the new value entered in the interface element, and then that value is sent back to both the field and the stepper to keep them in sync with the current data values.

So for example, if you have outlets to myTextField and myStepper, which you want to be setting the values for myInteger in your controller, you can create an action method and connect both the text field and stepper to call the action.

- (IBAction)myAction:(id)sender
{
myInteger = [sender intValue];
[myTextField setIntValue:myInteger];
[myStepper setIntValue:myInteger];
}

This way, the new value will be read from whichever widget changed, but both will be synced up no matter which one sent the message.

If you have a large number of text fields and steppers to deal with, you might consider creating a matrix of text fields and a matrix of steppers rather than having lots of individual outlets pointing to all the controls. You can then have a generic message sent by the cells in each matrix and differentiate between the various cells by what row/column they're in. I can explain this in further detail if you'd like.

--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSStepper and NSTextField changes
      • From: Brad Oliver <email@hidden>
  • Prev by Date: Re: Subject: Re: Cocoa Book
  • Next by Date: Re: NSStepper and NSTextField changes
  • Previous by thread: Re: NSStepper and NSTextField changes
  • Next by thread: Re: NSStepper and NSTextField changes
  • Index(es):
    • Date
    • Thread