<分区>
查看我下面的代码。我正在尝试使用 uialertviewcontroller 添加文本字段。现在,当我的两个文本字段中都没有输入时,我需要禁用两个操作按钮。该怎么做??
请提出一些可能的解决方案。谢谢!!
<分区>
查看我下面的代码。我正在尝试使用 uialertviewcontroller 添加文本字段。现在,当我的两个文本字段中都没有输入时,我需要禁用两个操作按钮。该怎么做??
请提出一些可能的解决方案。谢谢!!
最佳答案
最初禁用按钮,然后在文本字段中有内容后重新启用它们。
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@"Info"
message:@"You are using UIAlertController with Actionsheet and text fields"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
NSLog(@"Resolving UIAlert Action for tapping OK Button");
[alert dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
NSLog(@"Resolving UIAlertActionController for tapping cancel button");
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[ok setEnabled:false];
[cancel setEnabled:false];
[alert addAction:ok];
[alert addAction:cancel];
将选择器添加到文本字段然后处理它:
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"iCloud ID";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
[textField addTarget:self action:@selector(textDidChange:) forControlEvents:UIControlEventEditingChanged];
}];
- (void)textDidChange:(UITextField *)textField {
if (textField.text.length > 0) {
// enable the buttons
}
}
要处理文本字段委托(delegate),您可以阅读以下文章:
关于ios - 如何在 uialertview Controller 的 uitext 字段中没有输入时禁用两个 uialertcontroller 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38909668/
相关文章:
iphone - iOS - 如何在 UITabBar 中重新加载不同的 ViewController
ios - 是否可以将dispatch_queue_t添加到NSMutableArray?
objective-c - 当我修改文件时发送 kevent NOTE_DELETE
ios - NSPredicate遍历关系(StackMob)
objective-c - UIPopoverController 取得控制权,不会放手
ios - UIAlertController 出现后自动关闭一小部分时间
ios - 关闭警报 View Controller 后, TextView 会失去色调