Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bymartin

macrumors newbie
Original poster
Jul 14, 2003
4
0
Hi,

I have a UITextField that I'd like to validate the input as currency. I looked into using NSFormatter and was able to create one, but the iphone library does not appear to have the setFormatter method to associate the NSNumberFormatter with the textfield.

Does anyone know how to make this association?

Maybe I should use NSCharacterSet instead and just check to make sure my input is part of a custom set (0-9 and .) using characterIsMember?
 

springframework

macrumors member
Mar 31, 2008
59
0
If you implement the UITextFieldDelegate and set the textfield.delegate = ...

then inside the delegate functions you can do any formatting/error processing/screen updates/... that you want.

-(BOOL)textFieldShouldReturn(UITextField *)textField{
if(...)
return YES;
else
return NO;
}


there are other functions that can be defined for UITextFieldDelegate
 

bymartin

macrumors newbie
Original poster
Jul 14, 2003
4
0
Thanks...I already have that part. My question was how to use NSNumberFormatter - but I can do it manually. I was just trying to figure out how to use this convenience class rather than coding it myself.
 

bymartin

macrumors newbie
Original poster
Jul 14, 2003
4
0
I have it working...I just made a custom NSCharacterSet and then parse my string and check for membership of each unichar. If it's not a member, I can return NO, display an alert, and have the user enter good input.
 

Sbrocket

macrumors 65816
Jun 3, 2007
1,250
0
/dev/null
You might want to file a bug report (http://bugreporter.apple.com/) just to let engineering be aware that it's not there for UIControl. It could be an intentional decision or it could just be something that got left out, but no one will ever review it if a bug isn't filed. Radar bugs are how the engineers work.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.