【发布时间】:2014-04-30 06:50:56
【问题描述】:
如何限制可以使用现有代码在 UIAlertView 的文本字段中输入的文本数量?
我是 iOS 应用开发的新手。
我的代码如下:
if(indexPath.row== 1){
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Enter Novena Day"
message:@"Please enter the day of Novena:"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok", nil];
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
UITextField *textField = [alertView textFieldAtIndex:0];
textField.keyboardType = UIKeyboardTypeNumberPad;
[alertView show];
}
【问题讨论】:
-
实现文本字段的委托,并实现检查有多少字符并禁止超过允许的代码。
-
您可以像对任何其他文本字段一样限制它。
-
那么我可以对文本字段使用典型的委托吗?
-
@LeoNatan 真的吗?不要仅仅因为使用了错误的标签就对问题投反对票,尤其是对于新用户。出于适当的原因投反对票,例如明显缺乏首先研究答案或未能提供足够的细节来提供帮助。
-
这是委托文本字段的正确方法吗 [textField setDelegate:shouldChangeCharactersInRange];
标签: ios objective-c uitextfield uialertview