0

From past few days I am facing a weird keyboard issue that is only happening in iPhone 5c only.

I am using objective-C for Development in Xcode-6.4

My environment target is ios7.

Here is How I am handeling 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];

}

To Deregister Notification I am writing this piece of code.To be sure I use -resignFirstResponder for every textField.

- (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];
}

And In submit button I have checked some condition and then I am showing an AlertView.

- (IBAction)submitClicked:(id)sender
{
if(validated)
 {    
    [self.view endEditing:YES];
    [self hideKeyBoard];
    [self.view resignFirstResponder]; 

    [self makeApiCall];
 }
}

Now when I get Success/Failure Response from server I am doing this.This is the block which runs after getting response from server:

-(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];


});

}

Problem When I get alertBox and press ok. Then keyboard opens up and closes automatically. This is happening i iPhone 5C only. I checked it in 4s,5s,6 and 6Plus. All are working fine.

If anyone knows about it please assist.

Rahul
  • 5,594
  • 7
  • 38
  • 92

2 Answers2

0

You are displaying alert at same time you are also doing popToRootViewController. May be this will cause problem.

  1. Display alert.
  2. Handle alert view method.
  3. Write [self.navigationController popToRootViewControllerAnimated:YES] in alert view's method.

    [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]; 
         }
    }];
    

Hope this will help you.

Ekta Padaliya
  • 5,743
  • 3
  • 39
  • 51
0

After Some Research I found this answer In stackOverflow.

Their is some change in the behaviour of AlertView in ios7 and in ios8.

I use this code to solve my issue:

[self performSelector:@selector(showAlertView) withObject:nil afterDelay:0.6];

For details answer please refer to this SO answer

Community
  • 1
  • 1
Rahul
  • 5,594
  • 7
  • 38
  • 92