How IOS resolves unable to hide the keyboard

Source: Internet
Author: User

Problem:

A uitableview is added to a parent view and a Uitextview (Uitextview to the bottom and the rest for the UITableView layout). When you click Uitextview, the response is normal. When you finish writing, you need to call [Uitextview Resignfirstresponder] to hide the keyboard. This causes the keyboard to be closed.

Reason:

When the click UITableView, the trigger is not uitextview, that is, the touch is UITableView. When the finger touches, the response chain begins to respond from the top of the view. When it arrives at UITableView, UITableView is inherited uiscrollewview, so the signal is answered by UITableView, that is, the UITableView touch method is executed. Therefore, Uitextview is unable to respond.

Workaround:

Extend the UITableView to allow it to filter the first response:

@implementation UITableView (Uitouch)-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event {[[Self NEXTRESP    Onder] Touchesbegan:touches withevent:event]; [Super Touchesended:touches withevent:event];} -(void) touchesmoved: (Nsset *) touches withevent: (Uievent *) event {[[Self nextresponder] touchesmoved:touches withevent    : event];    [Super Touchesended:touches Withevent:event]; }-(void) touchesended: (Nsset *) touches withevent: (Uievent *) event {[[Self nextresponder] touchesended:touches WithEven    T:event]; [Super Touchesended:touches withevent:event];} @end

Where needed, import this.

Call in the class and determine if it is not the uitableview, if not, then you can put the keyboard away.

-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event {[Super Touchesbegan:touches withevent:event];    UITableView *teableview = (UITableView *) [touches anyobject];    if (Teableview! = Self.tableview) {[TextView resignfirstresponder]; }}

===== ===== ===== ===== ===== ===== ===== ===== =====

There is also a method that is not recommended for use.

That is, when the keyboard bouncing up, put a clickable view on the top level, you can.



How IOS resolves unable to hide the keyboard

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.