【发布时间】:2016-08-31 10:22:30
【问题描述】:
我有问题。
我有四个文本字段,但我不知道如何检查输入字符串的文本字段。
-
nameField不超过 10 个字符串 -
ageField检查是否为数字 -
sexField查男是女
这是我的代码:
- (IBAction)addComment:(id)sender {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Commend" message:nil preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Please input your name:";
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Please input your age:";
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Please input your sex:";
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Please input your commend:";
}];
UIAlertAction *sendAction = [UIAlertAction actionWithTitle:@"send" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
UITextField *nameField = alertController.textFields[0];
UITextField *ageField = alertController.textFields[1];
UITextField *sexField = alertController.textFields[2];
UITextField *commentField = alertController.textFields[3];
UIAlertController *successAlertController = [UIAlertController alertControllerWithTitle:@"Alert" message:@"Success" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self.navigationController popViewControllerAnimated:YES];
}];
[successAlertController addAction:okAction];
[self presentViewController:successAlertController animated:YES completion:nil];
}];
[alertController addAction:sendAction];
[self presentViewController:alertController animated:YES completion:nil];
}
谢谢!
【问题讨论】:
-
您想在输入时检查是否输入了正确的数据?还是按下发送按钮后?
-
你如何检查它的男性或女性
-
为什么你不使用年龄和性别字段的选择器????
-
我想在输入结束时检查并转到下一个文本字段
标签: ios objective-c iphone uitextfield