Summary of Itextview recycling or turning off keyboard usage in Uios development _android

Source: Internet
Author: User

iOS development, found Uitextview not like Uitextfield in Textfieldshouldreturn: This method, then to implement Uitextview close the keyboard, you must use other methods, the following is a few ways to use.

1. If your program has a navigation bar, you can add more than one done button on the navigation bar, used to exit the keyboard, of course, first real uitextviewdelegate.

-(void) textviewdidbeginediting: (Uitextview *) TextView { 
Uibarbuttonitem *done = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemdone target:self Action: @selector (Leaveeditmode)] autorelease]; 
Self.navigationItem.rightBarButtonItem = done; 
} 
-(void) textviewdidendediting: (Uitextview *) TextView { 
Self.navigationItem.rightBarButtonItem = nil; 
} 
-(void) Leaveeditmode { 
[Self.textview resignfirstresponder]; 
}

2. If you do not use enter in the TextView, you can use the return key as a response to exit the keyboard.

-(BOOL) TextView: (Uitextview *) TextView Shouldchangetextinrange: (nsrange) Range Replacementtext: (NSString *) text 
{ 
if ([text isequaltostring:@ "\ n"]) { 
[TextView resignfirstresponder]; 
return NO; 
} 
return YES; 

This way, whether you're using the ENTER key on your computer's keyboard or using the return button on your pop-up keyboard, you can get out of the keyboard.

3. The third method feels better than either of the above, which is to put a view on the keyboard above to place the done button that exits the keyboard.

 Uitoolbar * TopView = [[Uitoolbar alloc]initwithframe:cgrectmake (0, 0, 320, 30)]; 
[TopView Setbarstyle:uibarstyleblack]; Uibarbuttonitem * Hellobutton = [[Uibarbuttonitem alloc]initwithtitle:@ "Hello" style:uibarbuttonitemstylebordered 
Target:self Action:nil]; Uibarbuttonitem * Btnspace = [[Uibarbuttonitem alloc]initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace 
Target:self Action:nil]; Uibarbuttonitem * Donebutton = [[Uibarbuttonitem alloc]initwithtitle:@ ' done ' style:uibarbuttonitemstyledone target: 
Self action: @selector (Dismisskeyboard)]; 
Nsarray * Buttonsarray = [Nsarray arraywithobjects:hellobutton,btnspace,donebutton,nil]; 
[Donebutton release]; 
[Btnspace release]; 
[Hellobutton release]; 
[TopView Setitems:buttonsarray]; 
[Tvtextview Setinputaccessoryview:topview]; 
-(Ibaction) Dismisskeyboard {[Tvtextview resignfirstresponder]; } 

The above is a small set to introduce the Uitextview recovery or the use of the keyboard to close the summary, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.