Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide keyboard in UIViewController on return button click->iphone

Hi I find some questions like that but they talk about textView, I have ViewController, with scrollView where are 6 textfield and one textView I want a function which makes the keyboard disappear on on done/return button click.I implemented functions resign to first responder, which hide my keyboard when i click outside of scrollView, but that is not exactly i want, because i like to make it disappear on button click too.

THanks for any help

like image 569
Csabi Avatar asked Mar 01 '11 07:03

Csabi


2 Answers

Set up a class that conforms to the UITextFieldDelegate protocol and make the delegate of your text fields an instance of this class. Implement the method:

- (BOOL)textFieldShouldReturn:(UITextField *)textField

As follows:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
like image 171
James Bedford Avatar answered Oct 25 '22 04:10

James Bedford


Hi i found it out so the point with textfields is to add this lines at viewdidload:

textFieldOne.returnKeyType = UIReturnKeyDone;
    textFieldCislo.delegate = self;
textFieldTwo.returnKeyType = UIReturnKeyDone;
    textFieldCislo.delegate = self;
...

And this implement method :

-(BOOL)textFieldShouldReturn:(UITextField *)theTextField {

    if (theTextField == textFieldOne) {
        [textFieldOne resignFirstResponder];
    }
...
}
like image 32
Csabi Avatar answered Oct 25 '22 04:10

Csabi