UITextField have to accept the numbers only by using UITableView.
You have to perform two steps:
UIKeyboardTypeNumberPad
, as mentioned by others.In
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
method check that entered string in numeric or not.You can use following method to check numeric value:
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if([self isNumeric:string])
return TRUE;
else
return FALSE;
}
-(BOOL)isNumeric:(NSString*)inputString
{
NSCharacterSet *cs=[[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet];
NSString *filtered;
filtered = [[inputString componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return [inputString isEqualToString:filtered];
}
If you have textFiled available while coding, set keyboardType property of UITextField.
textField.keyboardType = UIKeyboardTypeNumberPad;
Or you can set the same with in xib file.
In your xib file select the textFiled and in the property list there is a field Keyboard select Number Pad