[英]Keyboard will appeared automatically in ios 8.3 while displaying alertview
Hi I am new for ios and in my app I have added one textfeild when I tapped on it keyboard is appearing and when I click return button I want to show alertview
. 嗨,我是ios的新手,在我的应用程序中,当我点击它时出现在键盘上,并且当我单击“返回”按钮时我想显示alertview
,所以我添加了一个alertview
。
And when I click alertview "ok" button I want to hide keyboard but it's not hiding help me please 当我单击alertview“确定”按钮时,我想隐藏键盘,但没有隐藏,请帮帮我
-(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];
}
try this 尝试这个
Direct UIView 直接UIView
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"Hello wolrd");
[yourtextfield resignFirstResponder];
[self.view endEditing:YES];
}
ScrollView 滚动型
create the one tapGesture
like 创建一个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];
}
Update 更新
-(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;
}
Just replace below function: 只需替换以下功能:
-(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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.