Ios iPhone 5c中的键盘隐藏/显示问题
从过去几天开始,我面临着一个奇怪的Ios iPhone 5c中的键盘隐藏/显示问题,ios,objective-c,iphone,keyboard,uikeyboard,Ios,Objective C,Iphone,Keyboard,Uikeyboard,从过去几天开始,我面临着一个奇怪的键盘问题,这只发生在iphone5c上 我正在使用objective-C进行Xcode-6.4 我的环境目标是ios7 以下是我处理键盘通知的方式 - (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWill
键盘问题,这只发生在iphone5c
上
我正在使用objective-C
进行Xcode-6.4
我的环境目标是ios7
以下是我处理键盘通知的方式
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
为了取消注册通知
我正在编写这段代码。为了确保我对每个文本字段使用-resignFirstResponder
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self hideKeyBoard];
[self.view endEditing:YES];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
- (void)hideKeyBoard{
[kAgeTextField resignFirstResponder];
[kSchoolTextField resignFirstResponder];
}
在submit(提交)按钮中,我检查了一些条件,然后显示了一个AlertView
- (IBAction)submitClicked:(id)sender
{
if(validated)
{
[self.view endEditing:YES];
[self hideKeyBoard];
[self.view resignFirstResponder];
[self makeApiCall];
}
}
现在,当我从服务器获得成功/失败响应时,我正在执行此操作。这是从服务器获得响应后运行的块:
-(void)SuccessfulWithServerInfo:(id)responseInfo
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
dispatch_async(dispatch_get_main_queue(),^{
[appDelegate hideProgressViewFromView:self.view];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"Thanks for coming" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[self.navigationController popToRootViewControllerAnimated:YES];
});
}
问题当我收到alertBox并按ok时。然后键盘自动打开和关闭。这种情况只发生在iPhone 5C上。我在4s、5s、6和6Plus中进行了检查。一切正常
如果有人知道,请协助。您在显示警报的同时也在执行popToRootViewController。可能这会引起问题
显示警报
处理警报视图方法
在警报视图的方法中写入[self.navigationController PoptorootViewController激活:是]
[UIAlertView showWithTitle:@"" message:@"Thanks for coming" cancelButtonTitle:@"OK" otherButtonTitles:nil] alertViewStyle:UIAlertViewStyleDefault tapBlock:^(UIAlertView *alertView, NSInteger buttonIndex, NSString *text)
{
if(buttonIndex == 1)
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
}];
希望这能对你有所帮助。经过一些研究,我在stackOverflow中找到了这个答案
它们是在ios7和ios8中AlertView行为的一些变化
我使用此代码来解决我的问题:
[self performSelector:@selector(showAlertView) withObject:nil afterDelay:0.6];
有关详细答案,请参阅无更改、、、我的所有文本字段都在表视图中…表视图是否会出现问题tableview位于显示alertview的同一个viewcontroller上?