从过去的几天开始,我面临一个奇怪的keyboard
问题,该问题仅发生在iPhone 5c
。
我在objective-C
Xcode-6.4
进行开发
我的环境目标是ios7
。
以下是我如何处理keyboard Notification
。
- (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];
}
致Deregister Notification
我正在撰写这段代码。确保我为每个textField使用-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];
}
在提交按钮中,我检查了一些条件,然后我显示了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并按确定。然后键盘会自动打开和关闭。这只发生在iPhone 5C上。我在4s,5s,6和6Plus中检查了它。一切正常。
如果有人知道,请协助。
答案 0 :(得分:0)
您正在显示警报,同时您也在执行popToRootViewController。可能这会引起问题。
在警告视图的方法中写[self.navigationController popToRootViewControllerAnimated:YES]。
[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];
}
}];
希望这会对你有所帮助。
答案 1 :(得分:0)
经过一些研究后我在stackOverflow中找到了这个答案。
它们是ios7和ios8中AlertView行为的一些变化。
我使用此代码来解决我的问题:
JLabel#setIcon(...)
有关详细信息,请参阅this SO answer