UITextView variable, allow to set text using special method only? - ios

I have a UITextField property inside a UIViewController class. I want to allow to set its text using a special method in view controller only. The goal is to move other view controller's elements according to a size of a text inside the text field.
Text field has editing option disabled so it can be setted in code only.
Way 1:
Subclass a UITextField. Looks too extra because I need to set the elements which doesn't belong to this text field. So I need to use a delegate (and as I understand it will be my own delegate only) etc.
Way 2:
Make text field property private. It is my current solution but I don't like that it is fully private.
Can anybody advice a better solution?

Related

Modify number keyboard in iOS

Need to create the iOS keyboard similar to attached image, it is possible any how with the native solution?
I have tried to assign a return key which is Done but i am getting following
You can create a custom input view with needed appearance.
To achieve this, you can use property inputView if UITextField:
The custom input view to display when the text field becomes the first
responder.
Here you can find a guide about custom input views.
Also I've created small example with custom input view without buttons: https://github.com/K-Be/KeyboardNotifications/tree/master_CustomInput .

Misuse of UITextField.inputView to get similar popup behavior of keyboard

I often want to put my own things in the same place the keyboard pops up, but for my own controls... such as putting a UIDatePicker there, or a custom UIPickerView, or whatever.
I came up with a clumsy way of getting this behavior by having a dummy UITextField and putting my custom view in its inputView property. Then when the user clicks on my item, I just trigger off the UITextField to display the view I've assigned to the inputView.
Then I got to wondering if there was a better less kludgey way to do this. I found this article Show UIPickerView like a keyboard, without UITextField where several people recommend the same thing I do.
My question is this. Is it common to (mis)use the UITextField in this manner?
Many times you will face a UITextfield that you would want to populate through a custom control other than the standrd keyboard. Thus the inputView method was declared and can be used.
What is recommended:
1- if the UItextfield is normal, use the keybard (don't change the input view)
2- if the value is numeric, show the numberpad in keyboard directly (textField.keyboardType = .numberPad)
3- if your textField is a date then you set the input view as a date picker.
4- sometimes you need a UITextField where you need to choose between stuff. Thus you develop your own custom UIPicker and set it as an input View.
5- If what you are tring to achieve don't fall in all the above then you can do your own inputView and assign it.
So in short don't be afraid, it is the normal thing to do!
Hope this helps!

Is it possible to add a Done key to ALL keyboards in an app?

Is it possible to add a done or cancel key which dismisses a keyboard to all keyboards in an iOS app? There are several posts asking how to dismiss a keyboard via a cancel or done button, but the solutions are on a field by field basis.
Are there any solutions that add this functionality globally so the code wont need to be duplicated for each textfield/area in an application?
Like #silentBob says in his answer, the inputAccessoryView of a text field is the view that’s displayed immediately above the keyboard when the text field is the first responder. If you didn’t want to write an extension on UITextField to override the -inputAccessoryView method, you could also create a subclass of UITextField to do the same, which would make it easier to determine which method is going to be called. You could also have multiple subclasses of UITextField to customize which button(s) appear. If you have a text field in a storyboard, you can simply change the class to your custom subclass, so while you have to go through and make those changes, you don’t have to do it in code.
Yes, you can add an extension to UITextField class, which should add a UIToolbar with Done and Cancel actions as UITextField inputAccessoryView.
Well, In that case you have to customise the keyboard, built your own keyboard and do whatever you need to do with your key in the keyboard.

How to set UIKeyboardType for custom UIView

I have implemented a custom control, which is a subclass of UIView and conforms to the protocol <UIKeyInput> to read the Keyboard input.
The problem is, that I want to show a numerical Keyboard instead of the regular one and I don't know how.

Application freezes after editing custom UITextField

I have a custom UITextField used for validating for non empty input, correct emails, passwords bigger than x characters etc.
The UITextField has a delegate to itself, since I do all the validation on the text field object itself. Not sure if this is the problem.
This custom UITextField is created in the .XIB file.
The text field sometimes locks the application when editing the text field itself. It also usually locks up when I press the "Next" button on the keyboard (for going to the next text field that needs to be filled).
Xcode doesn't give back an error (such as a loop-error, which I was assuming it was), the application just locks up. This doesn't happen all the time, but usually, if I stress test it with text, then press "Next", it's likely to lock up.
The app doesn't crash...it doesn't go back to the main screen, but it really just locks up, and stays unresponsive.
Any ideas? Let me know if you need more info to figure this out. I'm at a loss at the moment.
edit: Solved, apparently it's not a good idea to set a UITextField's delegate to itself. What I ended up doing is creating a separate class that deals specifically as being the delegate for the UITextField and doing all the logic in that class. That class would also have a property connected to the text field it is a delegate for.
I'll also write the answer here:
Apparently it's not a good idea to set a UITextField's delegate to itself, because it can end up going into a loop.
What I ended up doing is creating a separate class that deals specifically as being the delegate for the UITextField and doing all the logic in that class. That class would also have a property connected to the text field it is a delegate for.

Resources