• 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: "Jay Rimalrick" <email@hidden>
  • Date: Sun, 16 Nov 2003 00:45:48 -0500

Here is the code:

- (void)controlTextDidChange:(NSNotification *)aNotification
{
if([aNotification object] == textField1)
float1 = [textField1 floatValue];
else if([aNotification object] == textField2)
float2 = [textField2 floatValue];

[self DoCalculations];
}

textField1 and 2 are IBOutlets

DoCalculations is a function that does calculations based on the values of float1
and float2

I hope this helps.

-jay


---------- Original Message ----------------------------------
From: Daniel Todd Currie <email@hidden>
Date: Sat, 15 Nov 2003 20:00:36 -0800

>Without looking at your source, I'd have no idea... Perhaps post the
>segment of code where you read the text field values, and any other
>code that would be useful.
>
>
>On 2003 Nov 15, at 18:20, Jay Rimalrick wrote:
>
>> 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
>>
>>
>>
>>
>>
>>
>>> I was suggesting the same thing as Louis, as well as the answer to
>>> your
>>> question... Perhaps it was not worded clearly/explicitly. (I
>>> suggested a delegate for your formatter, which does not actually work,
>>> since NSFormatters cannot have delegates).
>>>
>>> You will need to set up a method to do the calculation in some other
>>> class. Then you can send a message to that method from your formatter
>>> using one of the performSelector: methods listed here:
>>>
>>> http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
>>> ObjC_classic/Classes/NSObject.html
>>>
>>> If you are unfamiliar with the use of selectors, I suggest you read
>>> the
>>> section describing their usage (also at the above link).
>>>
>>>
>>> On 2003 Nov 15, at 15:22, Jay Rimalrick wrote:
>>>
>>>> Louis and all
>>>>
>>>> This is a great feature that I was not aware of. However, I have one
>>>> more
>>>> question. If I would want to do calculations on the text entered as
>>>> it is
>>>> entered where would i do that?
>>>>
>>>> Thanks,
>>>> jay
>>>>
>>>>
>>>>> Hello...
>>>>>
>>>>> Another approach would be to subclass NSNumberFormatter, and
>>>>> override
>>>> the
>>>>>
>>>>> - (BOOL)isPartialStringValid:(NSString *)partialString
>>>>> newEditingString:(NSString **)newString errorDescription:(NSString
>>>>> **)error;
>>>>>
>>>>> method. That formatter method should be called for every character
>>>>> entered into the textfield, and you can do whatever verification or
>>>>> notification you want.
>>>>>
>>>>> Once you've made your subclass of the formatter, just read the
>>>>> header
>>>>> file into IB and you will be able to select it in the "custom
>>>>> class"
>>>>> pane of the Interface Builder inspector for the formatter, so that
>>>>> the formatter will be an instance of your subclass instead of the
>>>>> standard NSNumberFormatter.
>>>>>
>>>>> Louis
>>>>>
>>>>>
>>>>>> i am using controlTextdidChange but it does not work when I have
>>>>>> the
>>>>>> textfield formatted to handle money or float values larger than 0
>>>>>> ... for
>>>> some
>>>>>> reason It will not pick up the decimal
>>>>>>
>>>>>> if i type in 1.2 it only recognized 12
>>>>>>
>>>>>> any idea?
>>>>>>
>>>>>>
>>>>>>> - (void)controlTextDidChange:(NSNotification *)aNotification
>>>>>>>
>>>>>>> At 5:51 PM -0500 11/14/03, Jay Rimalrick wrote:
>>>>>>>> I want to capture a number being typed into an NSTextField
number
>>>>>>>> by
>>>>>>>> number including float values. Thus entering 1.2 would work like
>>>>>>>> this
>>>>>>>>
>>>>>>>> type 1 -> (calculations are done for the value 1)
>>>>>>>> type . -> (calculations are done for the value 1.)
>>>>>>>> type 2 -> (calculations are done for the value 1.2)
>>>>>>>>
>>>>>>>> What delegate method should I use for this? I am also trying to
>>>>>>>> use an
>>>>>>>> Interface Builder formatter on the NSTextField to keep the values
>>>> positive.
>>>>>>>>
>>>>>>>> Thanks in advance,
>>>>>>>> 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.
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>> ________________________________________________________________
>>>> Sent via the WebMail system at 1st.net
>>>> _______________________________________________
>>>> 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.
>>>>
>>>
>>>
>>
>>
>>
>>
>>
>> ________________________________________________________________
>> Sent via the WebMail system at 1st.net
>>
>>
>>
>>
>>
>
>




________________________________________________________________
Sent via the WebMail system at 1st.net
_______________________________________________
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: NSTextField getting input number by number
      • From: "Louis C. Sacha" <email@hidden>
  • Prev by Date: Re: NSTextField getting input number by number
  • Next by Date: Re: Instantiating Objects in Nib Files
  • Previous by thread: Re: NSTextField getting input number by number
  • Next by thread: Re: NSTextField getting input number by number
  • Index(es):
    • Date
    • Thread