0

I am working with an Ipad. My view controller has two text fields. One will accept regular text. The second I want only numbers. As usual I set the keyboard type on the second text field to the decimal keyboard.

I would like to restrict the second field to only numbers. I have found several possible solutions on this site but none seem to work. I don't seem to be able to select the second text field for the restrictions I'm looking for.

Any suggestions would help this new programmer. THX

STaylor
  • 45
  • 5

1 Answers1

1

You must adopt the UITextFieldDelegate protocol and implement the following method in your related UIViewController.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

 //place your checking code here...

}

Method reference

SO post related to your question.

Community
  • 1
  • 1
Michael
  • 6,561
  • 5
  • 38
  • 55
  • Thanks. I had set the delegate and set the delegate to the text field in the view did load. Problem solved. THX – STaylor Jan 31 '15 at 23:20