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];
}