【发布时间】:2017-12-06 07:16:17
【问题描述】:
我想在确定按钮单击文本字段后在文本字段中输入文本之前显示警报,但我正在显示警报但文本字段不可编辑。
if(textField == contractValueField)
{
[self showAlertWithTitle:@"Information" textfield:contractValueField];
return YES;
}
我搜索了很多网站,但使用 UIAlertView 没有得到正确答案,它正在工作,但我想使用 UIAlertController。我的项目中有 20 多个文本字段,每个文本字段都会在编辑开始前显示警报。
- (void)showAlertWithTitle:(NSString *)title textfield:(UITextField*)textfield
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:@"Please enter Amount in Lakhs" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
[textfield becomeFirstResponder];
}];
[alert addAction:ok];
[self.navigationController presentViewController:alert animated:YES completion:nil];
}
【问题讨论】:
-
你的 showAlertWithTitle: 方法被调用了吗?
-
是的,它正在调用,但按确定后文本字段不可编辑
-
试试 [self presentViewController],我认为它不起作用
-
不,它不工作
-
尝试在dismissViewController的完成块中加入becomeFirstResponder
标签: ios objective-c uitextfield uialertcontroller