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!