更新时间:2023-11-28 23:29:46
按照以下步骤操作,可能会有所帮助:
Follow below steps, may it help:
将 delegate
和 tag
设置为 UIAlertController
文本字段.
Set delegate
and tag
to UIAlertController
textfields.
现在使用 UITextField
委托方法 shouldChangeCharactersInRange
在键入时验证文本或使用 textFieldDidEndEditing
在文本字段结束编辑后进行检查.检查使用它的标签来区分 textFields.
Now use UITextField
delegate method shouldChangeCharactersInRange
to validate text while typing OR use textFieldDidEndEditing
to check after textfield end editing . Check using it's tag to differentiate between textFields.
喜欢
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if(textField.tag==TxtNameTag){
//Validate Name textField
}
//Same way for other textFields
return YES;
}
OR 使用 textFieldDidEndEditing
在 textField 结束编辑时进行验证.
OR Use textFieldDidEndEditing
to validate while textField end editing.