Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard will appeared automatically in ios 8.3 while displaying alertview or alertcontroller

I have updated Xcode 6.3 and ios8.3 check my code. then it gives me weird result.

here is first screen of my demo app. here is one textfield. when I type somethin in textfield keyboard open.

enter image description here

after typing completed. I have clicked on show alert button. I have displayed alert and output will be following.

enter image description here

After click on cancel. I have displayed another alert then weird result keyboard should not open but when click on cancel button. display another alert and keyboard will appear automatically.

here is next screen output

enter image description here

following is the code

- (IBAction)MethodShowAlert:(id)sender 
 {

[tmptxtField resignFirstResponder];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Check Alert textField" message:@"keyboard should not be open" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil];
[alert show];
 }

 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  {
    [self showCustomAlertWithTitle:nil];
  }


-(void)showCustomAlertWithTitle:(NSString *)title{
      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Now Check" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];

      [alertView show]
  }
like image 435
Vinod Jadhav Avatar asked May 28 '15 06:05

Vinod Jadhav


People also ask

How do I enable keyboard in iOS simulator?

Select the iOS simulator window by click it. Click the simulator menu Hardware —> Keyboard, check the Connect Hardware Keyboard sub-menu, and then uncheck it at once. Now the keyboard will be prompted automatically when you click the text field or text view UI component in the iOS simulator.

Why is my onscreen keyboard not working on my iPad?

Sometimes, you’re using an iPad but the onscreen keyboard doesn’t show up where you expect it. There could be one of several things going on, including trouble with a Bluetooth keyboard or third-party keyboard apps. Here’s what may be wrong—and how to fix it.

How to fix iOS simulator keyboard hidden issue?

Click the simulator menu Hardware —> Keyboard, check the Connect Hardware Keyboard sub-menu, and then uncheck it at once. Now the keyboard will be prompted automatically when you click the text field or text view UI component in the iOS simulator. 2. Fix iOS Simulator Keyboard Hidden Issue Method Two.

How to use auto-correction and predictive text on iPhone?

Use Auto Correction on iPhone How to use Auto-Correction and predictive text on your iPhone, iPad, or iPod touch - Use Auto-Correction 1 Open the Settings app. 2 Tap General > Keyboard. 3 Turn on Auto-Correction. By default, Auto-Correction is on. See More....


2 Answers

In my case i tried hiding keyboard, before showing alert, so it will not save keyboard in memory to present it again after dismissing it self.

for that you just need to dismiss keyboard which will take default animation time to hide, only then you should present alert view then it will not save that keyboard.

you must put around .6 second gap in hiding keyboard and presenting alert

  [YOUR_TEXT resignFirstResponder];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{


                    _alertVw = [[UIAlertView alloc] initWithTitle:@"" message:@"message." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

                    [_alertVw show];
});
like image 96
Abhishek Avatar answered Nov 09 '22 02:11

Abhishek


Yep, it's strange.

But since iOS 8, I suggest to use the UIAlertController instead of UIAlertView.

Replace your code with this one:

- (IBAction)MethodShowAlert:(id)sender
{

    [tmptxtField resignFirstResponder];

    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"Check Alert textField"
                                                                              message:@"keyboard should not be open"
                                                                       preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
                                                            style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction *action) {
                                                              [self showCustomAlertWithTitle:@"Now Check"];
                                                          }];

    [alertController addAction:cancelAction];

    [self presentViewController:alertController animated:YES completion:nil];
}


-(void)showCustomAlertWithTitle:(NSString *)title{

    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:title
                                                                              message:nil
                                                                       preferredStyle:UIAlertControllerStyleAlert];

    [self presentViewController:alertController animated:YES completion:nil];
}

The keyboard will not show after the click on the button.

like image 34
Lapinou Avatar answered Nov 09 '22 02:11

Lapinou