When viewDidLoad set textField editable / enable keyboard - ios

I have an app with a UITextField. When the containing view appears, I want a keyboard to slide up and begin editing this text field. Not sure how I would go about doing this?
I've tried:
func viewDidLoad {
textField.editing == true
textField.selected == true

In viewWillAppear add a call to becomeFirstResponder, something like this:
[textField becomeFirstResponder];
or in Swift:
textField.becomeFirstResponder()

Related

IQKeyBoardManager : Hide keyboard for a specific textfield

In my app I have a form where the user fills out his/her information, the form has some textfields and amongst those is one where the user can select their country. This textfiled is a dropdown which when active displays a dropdown (tableview) with the list of countries to select. I have created a demo project, to reproduce the issue and share it here.
In this demo, I have add 3 textfields, when the user goes to the second textfiled, using the next button on the keyboard, a tableview is displayed. Now what I want to achieve is my keyboard should hide when the dropdown tableview is displayed.
I have put in quite some time trying to figure this out but has no success.
Here is the link to the demo project:
https://github.com/tejaskutal/IQKeyboardManagerDemo
Any help is greatly appretiated.
P.S: For some weird reason, when you click next when the first textfiled is active, it jumps to the third one first and then goes to second textfield after next is clicked one more time. However, this has nothing to do with the original problem so I left it there.
No need to handle different delegate. In your viewDidload you can do something like,
yourTextField.inputView = UIView.init(frame: CGRect.zero)
yourTextField.inputAccessoryView = UIView.init(frame: CGRect.zero)
so, for that textfield keyboard or toolbar will not be appeared.
You can use your UITextField's delegate and implement the textFieldShouldBeginEditing. Something like
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
if textField == theTextFieldToIgnore {
view.endEditing(true)
return false
}
}
As for your textField chaining, you should implement the textFieldShouldReturn
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if textField == firstOne {
textField.resignFirstResponder()
secondOne.becomeFirstResponder()
}
return true
}
Return key Action which textfield you want to resign
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[self.yourTf resignFirstResponder];
}

How to set keyboard as inputview in UItextfiled

I have one UItextfiled and in viewdidload i set his input view property as nil like this.
textField.inputView = nil
In in my view i have one button when i click on the button i have to set the textfield's inputview property as keyboard how can i do this.please help me.
I'm not exactly sure what you want to do, but probably you want your textField to became active, with a keyboard. That is done with
[textField becameFirstResponder];
and other way around is
[textField resignFirstResponder];

How to make the bottom toolbar float just above on the soft keyboard when the Textfield get focus

I add a toolbar in bottom of UIViewController and put a TextField on the toolbar, but when I hit the TextField ,the textfield is covered by popup-ed soft keyboard and Can't see it.
So, How to float the toolbar just above on the soft keyboard when the Textfield get focus.
There is a property called inputAccessoryView. When a textField is tapped you can call it like this:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
textField.inputAccessoryView=self.accessoryToolBar;
return YES;
}
this will call the toolbar on top of your keyboard.

How to move to next screen on click of Read only text field iOS

I have a textfield that is readonly. I have another Search View Controller(VC) also. My aim is when the user clicks on readonly textfield it should open the searchVC. I tried attaching Push seque to SearchVC but it's not working. Tried same with a button and works seamlessly.
Pls suggest whats the approach for this.
You can use gesture to your textfield
or
You can use custom button above the textfield. You have to show/hide the button on textfield disabled/enabled
try this
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField.tag==1)
{
//write alert view to check "click on this text filed alert is appearing"
return NO;
}
else if (textField.tag==2)
{
//it's behave normal uitextfiled
return YES;
}
}

objective c textField: selectAll text doesn't always work

I implemented this in the UITextField delegate:
-(void)textFieldDidBeginEditing:(UITextField *)iTextField {
[iTextField selectAll:iTextField];
}
My text field contain text.
When tapping on it, the keyboard goes up and all text selected.
when dismissing the keyboard and tapping again, no text selected (just blinking cursor).
when dismissing the keyboard and tapping again, all text selected again.
Any clue why does no text selected at the second tap?
have you tried with this?
textField.selectedTextRange = [textField textRangeFromPosition:textField.beginningOfDocument toPosition:textField.endOfDocument];
EDIT 1:
Now is going to work :), this call will be at the end of the queue
[textField performSelector:#selector(selectAll:) withObject:nil afterDelay:0.0];
I call selectAll in viewDidAppear works.

Resources