switching between different inputViews for the same textfields - ios

In my app, I have a textfield that takes its input from a picker view. However, the user could not find his preferred option so I added above the textfield a small button resembling a keyboard. Once the button is pressed the textfield's picker view should disappear and the keyboard should appear instead so that the user enter his preferred data. So how can I do that? I tried resigning it as first responder and then making it become the first responder hoping the picker could be released as the input view but it didn't work. Adding a textfield as an accessory input view will not look right (having two textfield the user should update the first one instead).

Related

Add Cancel Button to UIKeyboard

I want to add a cancel button to hide the keyboard if the user wants to. I cant find any solution for swift 3.
Take a look at the documentation of a UITextField's inputAccessoryView: https://developer.apple.com/reference/uikit/uitextfield/1619627-inputaccessoryview
Assigning a view to this property causes that view to be displayed above the standard system keyboard (or above the custom input view if one is provided) when the text field becomes the first responder. For example, you could use this property to attach a custom toolbar to the keyboard.
I recommend to assign a UIToolbar that contains your cancel button to the inputAccessoryView of the UITextField that needs the cancel button. Then hook up an action to the button that resigns the first responder from the UITextField.

What is the correct approach for dismissing the keyboard when using a UITextView?

I am wondering what the best approach for dismissing a keyboard is when using a UITextView. At the minute for UITextFields I dismiss the keyboard when the return button is pressed. However for the TextView I want to have the return button actually add new lines so there is no additional buttons remaining to close.
What if any is the current "standard" approach for dealing with this issue? For example is it to add an additional button on the screen or is there another approach?
Thanks
On the iPad there is a "dismiss" button on the keyboard. For iPhones, add an inputAccessoryView to the UITextView. Put a "dismiss" button there.
If you have several fields (text fields, text views, etc.) in some sort of form, you could have a standard inputAccessoryView for all of them. Include a "Next" button (to go to the next field) and a "Done" button (to dismiss the keyboard).

Different popover for editing and non editing text field

Ok, sorry if the title is a little off. Hope I explain it better here. What I want to do is have a popover (iPad app) that will do different things based on the state of a UITextField. So if the user is typing in that text field and then taps the popover button, the popover appears and if the user taps something in that popover it will get added to that text field (think something like adding often used text). In this situation the popover will only disappear when the text field finishes editing.
However if the user taps the popover button when the text field is not editing then that list of items still appears but now it should disappear if the user taps outside the popover.
I hear something about pass-through views, but I'm not certain that is what I need.
Does anybody know a good way to do this?
The passthrought views are views outside the popover that don't cause it to dismiss automatically. When you want to dismiss the popover from your code when the textfield has finished editing call [myPopover dismissPopoverAnimated:YES].
For adding text blocks into the textfield I think delegation is the right thing to do. You set the your main view as the delegate of the conten view of the popover and each time a text block in the popover is selected you tell the delegate to add this block to the textfields text.
When you want to prevent the popover from dismissing while the textfield is being edited you should implement the UIPopoverControllerDelegate methode popoverControllerShouldDismissPopover:.

How to display virtual keyboard in ios6 Simulator

How do you display the virtual keyboard in ios6 Simulator (iphone or iPad) ? I've tried the toggle keyboard option, but nothing appears, can you only make it appear with code? and if so, how?
Thanks for any advice.
You can't show the keyboard without a 'target'. The system needs to know where it should send the entered text to.
So if you have a subclass of UIView that accepts text input (UITextField for example), the keyboard is either shown when the user taps that view or you can programmatically trigger it by calling:
[textField becomeFirstResponder];
From iOS-Documentation Managing the Keyboard:
Displaying the Keyboard
When the user taps a view, the system automatically designates that view as the first responder. When this happens to a view that contains editable text, the view initiates an editing session for that text. At the beginning of that editing session, the view asks the system to display the keyboard, if it is not already visible. If the keyboard is already visible, the change in first responder causes text input from the keyboard to be redirected to the newly tapped view.
Because the keyboard is displayed automatically when a view becomes the first responder, you often do not need to do anything to display it. However, you can programmatically display the keyboard for an editable text view by calling that view’s becomeFirstResponder method. Calling this method makes the target view the first responder and begins the editing process just as if the user had tapped on the view.
If your application manages several text-based views on a single screen, it is a good idea to track which view is currently the first responder so that you can dismiss the keyboard later.

How to send open uikeyboard back while opening other subview?

In my application I have one uiview.
I am adding another subview to this view which contains one textfield.
when user clicks that field then it display the keypad.
This subview also contains one add and delete button.
when user clicks on that button another view is opened which is also the subview of main view and that view contains selection list in the table.
The problem here is when user types something in textfield so keyboard is open.
if user does not dismiss that keyboard and clicks on add button to select from selection list then only half of the selection list is visible because keyboard is still open.
I want to send the keyboard back.
Here i do not want to dismiss the keyborad.while user clicks the add button.i only want to send it back to the selection view.when user is done with selection view keyboard should be open as it is.How can i solve this issue?
If you want the keyboard to go away, you need to dismiss it when they click on the button by using [yourTextField resignFirstResponder];.
If you want it to come back when they select an item, you will need to call [yourTextField becomeFirstResponder];.

Resources