• 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: NSTextField getting input number by number
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextField getting input number by number


  • Subject: Re: NSTextField getting input number by number
  • From: "Louis C. Sacha" <email@hidden>
  • Date: Sat, 15 Nov 2003 22:31:21 -0800

Hello...

Here's something you might want to check:

Your delegate method is probably something like this

- (void)controlTextDidChange:(NSNotification *)aNotification
{
NSString *string = [[[aNotification userInfo] objectForKey:@"NSFieldEditor"] string];
float inputValue = [string floatValue];

// your code to calculate new values and update your display...
[self calculateStuffWithFloat:inputValue];
[self updateInterface];
}

The problem might be that your calculation/update methods or code in your delegate method is updating the value in the field that is being edited.

In other words, you get a text edited notification saying the text is now "1."
You get the value from the string (1) to do your calculations, and possibly store the value (1) somewhere.
Your update method or code updates your interface, including the text field being edited, using your calculations or a stored value.
Now the text field has the string "1" because your update code reset the field's value behind the scenes, so when you type "2" expecting to get "1.2" you will instead end up with "12"...

Try adding a line to log out the string and your calculated values using NSLog in the delegate method (controlTextDidChange:).

NSLog(@"string is -%@-, input value is %f",string,inputValue);

Run the program and type stuff into the textfield and see what the log in ProjectBuilder says after each key you type.
Then, comment out your update code (in the example above, the line with [self updateInterface]; ), and run it again typing the same thing into the textfield.
If it works properly when the update code is commented out, then you need to fix your code so it doesn't update the textField while it is being updated (or use seperate methods, one which just updates the other stuff for use from the delegate method, and one that calls that other method and also updates the textfield which you can use as your general update method).

Louis


I still have the problem no matter if I use the formatter provided with interface builder or make my own that I cannot get float values. I am overriding the function controlTextDidChange and here is the problem that I am encountering.

I enter '1' and it understands it is a one. I then enter a decimal point makeing it '1.' and the computer understands a one again simplifying my '1.' thus when I enter another number it results in '12' instead of '1.2'

How can I resolve this?

Thanks again for everyone's great help I know we be able to solve this problem.

-jay
_______________________________________________
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.

References: 
 >Re: NSTextField getting input number by number (From: "Jay Rimalrick" <email@hidden>)

  • Prev by Date: Re: Instantiating Objects in Nib Files
  • Next by Date: Writing an NSArray to disk
  • Previous by thread: Re: NSTextField getting input number by number
  • Next by thread: Re: NSTextField getting input number by number
  • Index(es):
    • Date
    • Thread