在 ios 8.3 显示 alertview 时键盘会自动出现
Keyboard will appeared automatically in ios 8.3 while displaying alertview
嗨,我是 ios 的新手,在我的应用程序中,当我点击它时,键盘出现,当我点击 return 按钮时,我添加了一个文本域,我想显示 alertview
.
当我点击 alertview "ok" 按钮时,我想隐藏键盘,但它没有隐藏,请帮助我
我的代码:-
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No network connection"
message:@"You must be connected to the internet to use this app."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[self performSelector:@selector(showAlertView) withObject:nil afterDelay:0.6];
[alert show];
return YES;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"Hello wolrd");
[mainscrollview endEditing:YES];
}
试试这个
直接 UIView
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"Hello wolrd");
[yourtextfield resignFirstResponder];
[self.view endEditing:YES];
}
ScrollView
创造一个tapGesture
喜欢
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap)];
singleTap.cancelsTouchesInView = NO;
singleTap.delegate = self;
[yourScrollviewName addGestureRecognizer:singleTap];
//method like
-(void)singleTap
{
[yourtextfield resignFirstResponder];
[self.view endEditing:YES];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"Hello wolrd");
[self singleTap];
}
更新
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"No network connection textField"
message:@"keyboard should not be open"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self singleTap];
}];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
return YES;
}
只需替换以下函数:
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[maintextfeild resignFirstResponder];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No network connection"
message:@"You must be connected to the internet to use this app."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
alert.delegate = self;
[alert show];
});
return YES;
}
嗨,我是 ios 的新手,在我的应用程序中,当我点击它时,键盘出现,当我点击 return 按钮时,我添加了一个文本域,我想显示 alertview
.
当我点击 alertview "ok" 按钮时,我想隐藏键盘,但它没有隐藏,请帮助我
我的代码:-
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No network connection"
message:@"You must be connected to the internet to use this app."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[self performSelector:@selector(showAlertView) withObject:nil afterDelay:0.6];
[alert show];
return YES;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"Hello wolrd");
[mainscrollview endEditing:YES];
}
试试这个
直接 UIView
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"Hello wolrd");
[yourtextfield resignFirstResponder];
[self.view endEditing:YES];
}
ScrollView
创造一个tapGesture
喜欢
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap)];
singleTap.cancelsTouchesInView = NO;
singleTap.delegate = self;
[yourScrollviewName addGestureRecognizer:singleTap];
//method like
-(void)singleTap
{
[yourtextfield resignFirstResponder];
[self.view endEditing:YES];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"Hello wolrd");
[self singleTap];
}
更新
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"No network connection textField"
message:@"keyboard should not be open"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self singleTap];
}];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
return YES;
}
只需替换以下函数:
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[maintextfeild resignFirstResponder];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No network connection"
message:@"You must be connected to the internet to use this app."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
alert.delegate = self;
[alert show];
});
return YES;
}