About Uialertview keyboard pop-up problem

Source: Internet
Author: User

Here is a record of my development encountered in a wonderful problem, after Baidu I found that the problem does exist, there are many people have encountered, today to write it out. In fact, we simply use Uialertview is not a problem, but when the UI has an input box, when the input is completed, we click the button pop-up Uialertview, click on the Uialertview above button to jump to the next page, then the problem comes, The keyboard will pop up on the next page. This problem is just beginning to appear, inexplicable wonderful, also looked for a long time, because in the simulator is not easy to detect, on the real machine is very obvious.

  • Below we simulate this phenomenon, here to give you a deeper impression, to avoid the same as I encountered this problem and tangled. directly on the code.
  • #import "ViewController.h"#import "ViewControllerOne.h"@interfaceViewcontroller () <UIAlertViewDelegate>@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.UIButton *button =[UIButton Buttonwithtype:uibuttontypecontactadd]; Button.center=Self.view.center;    [Self.view Addsubview:button];    [Button addtarget:self Action: @selector (click) forcontrolevents:uicontroleventtouchupinside]; Uitextfield*textfield = [[Uitextfield alloc] Initwithframe:cgrectmake ( -, -, -, -)]; Textfield.backgroundcolor=[Uicolor Redcolor];    [Self.view Addsubview:textfield]; [Self obserkeyboard];}#pragmaMark-Keyboard Monitoring-(void) Obserkeyboard {[[Nsnotificationcenter defaultcenter] addobserver:self selector: @selector (keyboardwillshow:) Name:uikeyboardwillshownotificationObject: nil]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardshow:) Name: UikeyboarddidshownotificationObject: nil]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardwillhide:) Name: UikeyboardwillhidenotificationObject: nil]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardhide:) Name: UikeyboarddidhidenotificationObject: nil];}- (void) Click {Uialertview*alertview = [[Uialertview alloc] Initwithtitle:@"Test Uialertview"Message@"Malpractice" Delegate: Self Cancelbuttontitle:@"Cancel"Otherbuttontitles:@"Determine",@"Is it fun?", nil]; [Alertview show];}#pragmaMark Keyboard Action-(void) Keyboardwillshow: (Nsnotification *) Notif {NSLog (@"The keyboard is going to pop-keyboardwillshow");}- (void) Keyboardshow: (Nsnotification *) Notif {NSLog (@"keyboard has popped-keyboardshow");}- (void) Keyboardwillhide: (Nsnotification *) Notif {NSLog (@"The keyboard will be hidden-keyboardwillhide");}- (void) Keyboardhide: (Nsnotification *) Notif {NSLog (@"Keyboard has been hidden-keyboardwillhide"); }- (void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) Buttonindex {if(Buttonindex = =1) {Viewcontrollerone*ctl =[[Viewcontrollerone alloc] init];    [Self.navigationcontroller Pushviewcontroller:ctl Animated:yes]; }}

    To put it simply, there is a Uitextfield and a button on one interface, and the button's Click event is pop-up uialertview. Let's talk about the steps to simulate a phenomenon.

  1. First enter the text in the Uitextfield
  2. After the input is done we click on the button, pop Uialertview this time we listen to the keyboard event in the console print the following
  3. When we click on the Uialertview OK button, push to Viewcontrollerone. Where the Viewcontrollerone code is the keyboard listening, the code is as follows:
    #import "ViewControllerOne.h"@interfaceViewcontrollerone ()@end@implementationViewcontrollerone- (void) viewdidload {[Super viewdidload]; //Do any additional setup after loading the view.[self obserkeyboard];}#pragmaMark-Keyboard Monitoring-(void) Obserkeyboard {[[Nsnotificationcenter defaultcenter] addobserver:self selector: @selector (keyboardwillshow:) Name:uikeyboardwillshownotificationObject: nil]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardshow:) Name: UikeyboarddidshownotificationObject: nil]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardwillhide:) Name: UikeyboardwillhidenotificationObject: nil]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardhide:) Name: UikeyboarddidhidenotificationObject: nil];}#pragmaMark Keyboard Action-(void) Keyboardwillshow: (Nsnotification *) Notif {NSLog (@"The keyboard is going to pop-keyboardwillshow");}- (void) Keyboardshow: (Nsnotification *) Notif {NSLog (@"keyboard has popped-keyboardshow");}- (void) Keyboardwillhide: (Nsnotification *) Notif {NSLog (@"The keyboard will be hidden-keyboardwillhide");}- (void) Keyboardhide: (Nsnotification *) Notif {NSLog (@"Keyboard has been hidden-keyboardwillhide"); }

    When we click Push to go in, we look at the print information of the console.

  4. Keyboard events are also monitored in the viewcontrollerone.

This will happen on the real machine. When push enters the next interface, a black line appears on the screen from right to left. In fact, the keyboard bouncing off and immediately back to the phenomenon caused by, of course, the solution I am currently using the Uialertviewcontroller to replace. Also said that, in order to solve this problem, I was in the first click on the button to use [Self.view Endediting:yes], to prevent the keyboard pop-up, but the actual is no eggs, the keyboard will still bounce out, Then I replaced all the Uialertviewcontroller.

About Uialertview keyboard pop-up problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.