Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom function for "done" button in toolbar #475

Closed
neilsekhon opened this issue Apr 1, 2016 · 9 comments
Closed

Custom function for "done" button in toolbar #475

neilsekhon opened this issue Apr 1, 2016 · 9 comments
Labels

Comments

@neilsekhon
Copy link

Is there a way to add a custom function for when the "done" button is pressed in the keyboard toolbar that is a different method for when the "return" key is pressed. For example, pressing "return" would dismiss the keyboard, while pressing "done" would present a view controller.

@Deepinder-Lakhi
Copy link

Keyboard Return Key Handling:-

If you would like to implement keyboard Return Key as Next/Done button, then you can use IQKeyboardReturnKeyHandler.(#38, #63)

  1. Create an instance variable of IQKeyboardReturnKeyHandler and instantiate it in viewDidLoad with ViewController object like this:-

@implementation ViewController
{
IQKeyboardReturnKeyHandler *returnKeyHandler;
}

  • (void)viewDidLoad
    {
    [super viewDidLoad];

    returnKeyHandler = [[IQKeyboardReturnKeyHandler alloc] initWithViewController:self];
    }
    It assign all the responderView delegates to self, and change keybord Return Key to Next key.

  1. set instance variable to nil in dealloc method.

-(void)dealloc
{
returnKeyHandler = nil;
}

@hackiftekhar
Copy link
Owner

If you just would like to get a callback when toolbar done button is pressed then you can check IQUIView+IQKeyboardToolbar.h, there is a method -(void)setCustomDoneTarget:(nullable id)target action:(nullable SEL)action;. This will not override default behaviour of done button and still dismiss keyboard, but you'll get a callback.

If you would like to get full control over done button then you can add your own UIToolbar to textField. In this case IQKeyboardManager will not override your toolbar and you'll take care of all the responsibility of your toolbar with your methods.

@arjavlad
Copy link

arjavlad commented Jan 19, 2017

@Deepinder-Lakhi I used your code. it works in iOS 9 but not working in iOS 10.
"textFieldDidEndEditing" is not being invoked in IQKeyboardReturnKeyHandler.m in iOS 10.

@w-i-n-s
Copy link

w-i-n-s commented Jul 11, 2017

Try to check text field when keyboard wants hide:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

@neetin
Copy link

neetin commented May 28, 2018

@hackiftekhar
I need to get action of Done button.
There is no setCustomDoneTarget() in v5.0.8. Can you please specify which function is there to achieve action of Done button?
BTW, I am using Swift 4 and iOS 11

@hackiftekhar
Copy link
Owner

hackiftekhar commented May 28, 2018

It's now moved to textField.keyboardToolbar.doneBarButton.setTarget(target:action:) please use this.

@jlubeck
Copy link

jlubeck commented Aug 9, 2018

This is not working for me

textField.keyboardToolbar.doneBarButton.setTarget(self, action: #selector(action))

The action never gets called, and it I check po relationshipField.keyboardToolbar.doneBarButton.target after that line, I get a nil response

@jlubeck
Copy link

jlubeck commented Aug 9, 2018

Interesting... if the textField has a delegate assigned, the target doesn't work If I removed the delegate, then it works fine. Is this expected? I still need the delegate for other functionality, so it sounds like a bug...

@hackiftekhar
Copy link
Owner

It is not expected. Please share demo project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants