Ios 使用UIAlertViewStylePlainTextInput显示UIAlertView,但不显示键盘
因此,我希望将Ios 使用UIAlertViewStylePlainTextInput显示UIAlertView,但不显示键盘,ios,ios6,uialertview,uikeyboard,Ios,Ios6,Uialertview,Uikeyboard,因此,我希望将UIAlertView与alertViewStyle一起显示为UIAlertViewStylePlainTextInput,但我希望它在显示时不会显示与其关联的键盘。有人有主意吗 另外,要了解我希望它的外观,请继续并在模拟器中使用alertViewStyle=UIAlertViewStylePlainTextInput显示警报视图,然后按return。我希望UIAlertView集中在屏幕上。我刚刚找到了几种方法来实现这一点。第一种也是最肮脏的方法是立即致电辞职第一响应者。虽然很难
UIAlertView
与alertViewStyle
一起显示为UIAlertViewStylePlainTextInput
,但我希望它在显示时不会显示与其关联的键盘。有人有主意吗
另外,要了解我希望它的外观,请继续并在模拟器中使用
alertViewStyle=UIAlertViewStylePlainTextInput
显示警报视图,然后按return。我希望UIAlertView
集中在屏幕上。我刚刚找到了几种方法来实现这一点。第一种也是最肮脏的方法是立即致电辞职第一响应者
。虽然很难看,但它很管用
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:@"Button", nil];
[alert setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alert show];
[[alert textFieldAtIndex:0] resignFirstResponder];
第二个选项是利用UITextFieldDelegate
协议,特别是textFieldShouldBeginEditing:
。使用此选项并将您的类设置为警报中文本字段的代理,您可以简单地返回NO
,并阻止键盘显示
请务必记住,除非在此方法中提供某种条件,否则将无法编辑文本字段
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:@"Button", nil];
[alert setAlertViewStyle:UIAlertViewStylePlainTextInput];
[[alert textFieldAtIndex:0] setDelegate:self];
[alert show];
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
return NO;
}
这只是一个理论,还没有经过检验:-
for(UIView *view in [alertView subViews])
{
if([view isKindOfClass:[UITextField class])
{
view.delegate=self
}
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
return NO;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title"
message:@"")
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *textField = [alert textFieldAtIndex:0];
textField.text = @"your text";
[alert show];
可以在IOS6和IOS7上工作为什么不想让键盘完全向上?我已经试过了,我注意到这样做不会使UIAlertView在模拟器的屏幕上居中。你也是这样吗?
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title"
message:@"")
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *textField = [alert textFieldAtIndex:0];
textField.text = @"your text";
[alert show];