-1

I want to add format currency for a textfield in a UIAlertview. However, I don't have any solution about this. Can you help me if you know solution?

Thanks

Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
iOS dev
  • 35
  • 1
  • 6
  • what type of research have you done already before you asked a community to solve your problem? – holex Apr 27 '14 at 12:33
  • possible duplicate of [How to properly format currency on ios](http://stackoverflow.com/questions/11787759/how-to-properly-format-currency-on-ios) – holex Apr 27 '14 at 12:34
  • I could have chosen any other posts which is about the formatted currencies, like e.g. http://stackoverflow.com/questions/5105227/is-there-a-simple-way-to-format-currency-into-string-in-ios – holex Apr 27 '14 at 12:36

1 Answers1

1
 NSNumberFormatter *formatter = [NSNumberFormatter new];
 formatter.numberStyle = NSNumberFormatterCurrencyStyle;
 NSString *cash = [formatter stringFromNumber:@5];

[[[UIAlertView alloc] initWithTitle:cash message:cash delegate:self cancelButtonTitle:nil otherButtonTitles:nil ] show];
Iraklii
  • 1,295
  • 13
  • 30
  • This is not my idea. Ex: I enter the value from keyboard: 200 then textfield of UIAlertview will show: $200 – iOS dev Apr 27 '14 at 12:26
  • Use UITextField Delegate. https://developer.apple.com/library/ios/documentation/uikit/reference/UITextFieldDelegate_Protocol/UITextFieldDelegate/UITextFieldDelegate.html – Iraklii Apr 27 '14 at 14:17
  • I know use it in a normal textfield but I don't know the way to use it in textfield of **Alertview**. – iOS dev Apr 27 '14 at 15:22
  • What style has your alert? Is it UIAlertViewStylePlainTextInput? If yes do this and use UITextField Delegate. textfield = [alert textFieldAtIndex: 0]; textfield.delegate = self; – Iraklii Apr 27 '14 at 17:31
  • it does not work although I added UITextField *textfield = [alert textFieldAtIndex: 0]; textfield.delegate = self; to viewDidload – iOS dev Apr 30 '14 at 19:13
  • As I talked above, I added 2 lines: UITextField *textfield = [alert textFieldAtIndex: 0]; textfield.delegate = self; to viewDidload. Then I put NSlog (@"go to delegate"); in - (BOOL)textFieldShouldReturn:(UITextField *)textField. However, it does not go into this method when I click Return button of the keyboard – iOS dev May 01 '14 at 06:12
  • //create alert view :alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Please input the Cash" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; alert.alertViewStyle = UIAlertViewStylePlainTextInput; [textfield setKeyboardType:UIKeyboardTypeDecimalPad]; [textfield becomeFirstResponder]; [alert show]; – iOS dev May 01 '14 at 06:14
  • ah I knew. I alloc alertView outside viewDidLoad – iOS dev May 01 '14 at 06:53