Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Xcode keyboard done button function

I just can't make the "Done" button to quit the keyboard.

I used this in my controller.h file

- (IBAction)textFieldDoneEditing:(id)sender;

and this for my controller.m file

- (IBAction)textFieldDoneEditing:(id)sender {
  [sender resignFirstResponer];
}

and I'm mixed up in wiring the .xib part.

like image 490
Kee Yen Yeo Avatar asked Apr 06 '12 05:04

Kee Yen Yeo


People also ask

What is resignFirstResponder Swift?

If you want that text control to stop waiting for input – which in turn dismisses the keyboard – you should call its resignFirstResponder() method, which passes the first responder baton to the next waiting component.

How do I move view up when keyboard appears in iOS SwiftUI?

You need to add a ScrollView and set a bottom padding of the size of the keyboard so the content will be able to scroll when the keyboard appears. All you have to do now is to embed your content inside the custom ScrollView .


1 Answers

Make the controller a delegate of the UITextField/UITextView in IB or from code like textField.delegate = self;

Editted: For this you need to declare the controller a delegate of UITextFieldDelegate/UITextViewDelegate as

@interface Controller : <UITextFieldDelegate> { ...

, then override the method:

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

for UITextField and

-(BOOL)textViewShouldEndEditing:(UITextView *)textView{
    [textView resignFirstResponder];
    return YES;
}

for UITextView

like image 99
skonb Avatar answered Oct 04 '22 14:10

skonb