thêm UITextFieldDelegate
trong tập tin tiêu đề của bạn (file .h)
txtfield_name.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
txtfield_name.delegate=self;
sau đó thêm phương pháp này
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSString *validRegEx [email protected]"^[0-9]*$"; //change this regular expression as your requirement
NSPredicate *regExPredicate =[NSPredicate predicateWithFormat:@"SELF MATCHES %@", validRegEx];
BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:string];
if (myStringMatchesRegEx)
return YES;
else
return NO;
}
Nó không phải là nó đã bị loại bỏ, nhưng thay vào đó nó không bao giờ có ở nơi đầu tiên. Bạn phải tạo ra bàn phím của riêng bạn để làm điều này. Xem: [Làm cách nào để tôi truy xuất tổ hợp phím từ bàn phím tùy chỉnh trên ứng dụng iOS?] (Http://stackoverflow.com/a/13351686/937822) – lnafziger