How to get keyboard with Next, Previous and Done Button?

IphoneCocoa TouchIos4Iphone Keypad

Iphone Problem Overview


I want to have a keyboard which has a Next,Previous and Done button on top of it.

I have seen that in many apps.

Especially where there are forms to be filled.

enter image description here

I want to achieve something similar to above keyboard

How can I get that?

Iphone Solutions


Solution 1 - Iphone

You'll find the answer on this other post. I checked the iOS Library and the inputAccessoryView of a UITextField is exactly what you're looking for !

Hope this helps !

Solution 2 - Iphone

I just created a class called BSKeyboardControls which makes it very easy to add the controls to a keyboard. The class, instructions and example code can be found here at GitHub.

The controls works for text fields and text views and are optimized for both iPhone and iPad.

Solution 3 - Iphone

-(BOOL)textFieldShouldBeginEditing: (UITextField *)textField 

{
     UIToolbar * keyboardToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];

    keyboardToolBar.barStyle = UIBarStyleDefault;
    [keyboardToolBar setItems: [NSArray arrayWithObjects:
                                [[UIBarButtonItem alloc]initWithTitle:@"Previous" style:UIBarButtonItemStyleBordered target:self action:@selector(previousTextField)],
                                
                                [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(nextTextField)],
                                [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                                [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(resignKeyboard)],
                                nil]];
    textField.inputAccessoryView = keyboardToolBar;

}



- (void)nextTextField {

  
    if (textField1) {

		[textField1 resignFirstResponder];
		[textField2 becomeFirstResponder];
	
	}

}

-(void)previousTextField
{

    if (textField2) {
		[textField2 resignFirstResponder];
		[textField1 becomeFirstResponder];
	}
	
 
}

-(void)resignKeyboard {

    [textField1 resignFirstResponder];
    [textField2 resignFirstResponder];

}

Solution 4 - Iphone

I have a utility class that basically does this for you.

https://github.com/kalvish21/CustomKeyboard

The idea is very simple. You have to add an accessory tool bar with bar button items on it. There's a delegate which defines where what that button will do.

Solution 5 - Iphone

https://github.com/hackiftekhar/IQKeyboardManager

This is the best keyboard handler I have seen so far. Very excellent way to manage Text inputs.

Some of its features

  1. ZERO LINE OF CODE

  2. Works Automatically

  3. No More UIScrollView

  4. No More Subclasses

  5. No More Manual Work

  6. No More #imports

Solution 6 - Iphone

This is a custom control which is placed directly above the keyboard. I think a UIToolbar can be used for that.

Previous and next passes around the firstResponder of the textFields and Done will do the resign as well as hide the toolbar.

To match the keyboard animation have a look at this code I found or at SO: "What is the iPhone's default keyboard animation rate?"

Solution 7 - Iphone

I have created a repository with an implementation of this feature that works on iPhone/iPad in all orientations and highly customizable.

Solution 8 - Iphone

As mentioned in other answers, it's the inputAccessoryView that you're looking for.

I would like to add an alternative way here, by using this cocoapods:

pod 'UITextField-Navigation'

All UITextFields will have two additional properties: nextTextField and previousTextField. You can then simply connect the nextTextField in the Interface Builder and the Previous, Next and Done buttons are added automatically for you, all functional, no more code is needed, no subclassing.

You can also customize the UI, add more buttons, etc as you want to.

enter image description here enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionParth BhattView Question on Stackoverflow
Solution 1 - IphoneErmiarView Answer on Stackoverflow
Solution 2 - IphonesimonbsView Answer on Stackoverflow
Solution 3 - Iphoneuser2021443View Answer on Stackoverflow
Solution 4 - IphoneKVISHView Answer on Stackoverflow
Solution 5 - Iphonei.AsifNoorView Answer on Stackoverflow
Solution 6 - IphoneNick WeaverView Answer on Stackoverflow
Solution 7 - IphoneDenis KutlubaevView Answer on Stackoverflow
Solution 8 - IphoneThanh PhamView Answer on Stackoverflow