Swift textfield deletes text when segmented control is touched. - ios

I have a textfield that inputs a number, and that number is converted into different units depending on the selection of a segmented control. My problem is that if the textfield is still being edited - and then the segmented control is selected, the textfield deletes the data that was entered.
Just to clarify: I enter an amount into the textfield, and while the text field is still selected I click the segmented control, and the textfield displays zero, erasing the value that I originally inputted.
I'm not positive if this is default behavior, or just the flow of my program.

Related

UIButtons pressed as Input for Text Field

Haven't found it on internet, searching on google I found Custom Keyboard as extension with is not what I need.
I need to make so that when you pressed my "Keyboard" on the bottom right (Its not actually a Keyboard, it is just a couple of UIButtons) the Inputs appear on the text field (Its the white space below ACTUAL CASH DEPOSIT).
So, when you press the text field, no keyboard should Appear, and When I start pressing the buttons of my "Custom Keyboard" the numbers should Appear.
I have found something similar in (Xcode 8 Swift 3). Using Custom Keyboard Extension with a particular Text Field But On my other Tap, Denominations I have multiple Input Fields. Like his image:
I know how to do all the code behind in terms of buttons pressed and calculations But I don't know how to make the input fields as a responder for my custom Keyboard.
You can't make it magically update - instead, I'd suggest binding all the buttons to a single function, and then then for instance use the tag property in IB to differentiate between them. Through that function update the text.
func didPressButton(button: UIButton) {
switch button.tag{
case 1: myTextField.text! += "1"
default: break
}
}
I'd caution you'll need to do some verification logic if you allow decimals so all numbers are valid.

Is there a way to default to the number pad when using the NamePhonePad Swift keyboard type?

Right now when using textField.keyboardType = .namePhonePad, it will automatically start out showing the alpha keyboard, and you then have to press the number toggle to see the number pad. Is there any way to reverse that and have the number pad show first as the default and then be able to manually toggle to the alpha keyboard?
I know it's possible to create a custom button to be able to toggle the keyboard type, as well as changing the keyboard type based on what they type into the text field, but I just want a way to change its default first keyboard.

Swift ios8: How to make single row picker with option for manual text entry?

I would like to give my iPhone App user the option of whether to use a picker (i.e., scroll wheel) or keyboard to input the value of a field. I'd like it to where the current value of the field effectively displays as isolated text (i.e., as a label, with the picker and keyboard hidden). But the user can change the field's value by either (A) performing a single tap on the label to reveal the keyboard so the user can type in a different value; or (B) perform a swipe on the label to reveal the picker so the user can user the picker to change the value. This will present a very clean interface in my opinion, without the clutter of the keyboard, text field, or picker unless the user changes the value. Help?
This control doesn't exist, but a possible solution would be to add a cell under the UIPickerView (assuming your using a table form) when the "Custom" option is selected and add a text field to that cell allowing custom input. Make sure you hide the cell if the UIPickerView value changes from "Custom" to avoid user confusion.

How to prevent keyboard input without Enter from changing TComboBox selection in Delphi?

A TComboBox behaves differently for mouse and keyboard input. If an item is highlighted using the mouse, it only becomes selected when clicked. However, when highlighted using the keyboard, using the arrow keys or by entering the first letter of the item, the selected item changes instantly.
How do I (cleanly) change the behavior of keyboard input to be more like mouse input? That is, an item becomes only the selected item when Enter is pressed (a "click").

How do I set a UITextField as the default input field at app launch

I am writing an iPhone app with a keypad and two TextFields on a single view. The user types into each of the text fields. Because I want to use an on-screen keypad, I disabled the the keyboard from launching when each TextField is selected. (I used the method suggested in this thread:
Disable UITextField keyboard?
So far so good EXCEPT the cursor doesn't blink in the either of the two TextFields until they are selected. If I just begin typing without selecting, the first textfield is filled. That's OK, but I would like to set the cursor flashing in that field so the user is notified that that is where the input will go unless they select the other field.
I did not create the text fields programatically. I created them with Interface builder.
How do I programatically select the desired starting text field (ideally some highlight would show up when selected). Right now I just got lucky and the field I want to be the default is the default.
How do I place the flashing cursor onto the right side of that text field.
...Dale
Call [myTextField becomeFirstResponder]; this will notify the receiver that it is about to become first responder in its window. That should set the Cursor in the UITextField.
To programmatically activate a field and make it your starting text field you should use UIResponder's becomeFirstResponder method, which all UITextFields inherit from.
[textField becomeFirstResponder];

Resources