Swype keyboard in iOS8 for normal and password (secure text entry) UITextField - ios

I've a login view with a normal and a secure text entry UITextFields.
In iOS8, using Swype keyboard, hitting the "Next" key doesn't go to the next responder as with the default keyboard.
If I open the keyboard hitting the password UITextField, it opens the default keyboard and it doesn't allow me to select Swype keyboard.
Apple doesn't allow custom keyboards for password
So, is there a way to know if the keyboard is missing that setting and force the next responder to open the default keyboard?

The keyboard change is done by default. If you just go to next responder, iOS will take care to change the keyboard to the iOS one. I'm using Swiftkey here and the change is automatic.
Are you delegating the textFields to your view controller? On mine, I use the textFieldShouldReturn method and go from one textField to the other (Swift code below):
func textFieldShouldReturn(textField: UITextField) -> Bool {
if(textField == usernameTextField) {
usernameTextField.resignFirstResponder()
passwordTextField.becomeFirstResponder()
} else {
passwordTextField.resignFirstResponder()
}
return true
}

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];
}

Keyboard blinks when moving to Next Responder

I implemented basic Next button on the Text Field using the following code:
func textFieldShouldReturn(textField: UITextField) -> Bool {
let didResign = textField.resignFirstResponder()
if(!didResign) {
return false
}
let myView = getParentView(textField)
dispatch_async(dispatch_get_main_queue(), { myView.nextField?.contentTextField.becomeFirstResponder() })
return true
}
What annoys me is that before nextField becomes First Responder, the keyboard disappears for a brief moment which looks ugly.
The effect is not always visible, sometimes it looks like the keyboard stayed up, sometimes it blinks fast.
Is there a way to resign first responder but still keep the keyboard up?
Move to next field whilst keeping the keyboard?
If you're working with UI, you should be on the main queue, so there's no need to dispatch_async to the main queue. Removing this code will make your code cleaner.
The method you're implemented determines the behavior of the app when the return key is pressed. Resigning first responder dismisses the keyboard, so if this is not the effect you want, don't resign first responder.

While displaying an alert in IOS, keyboard does not resign from View

While displaying an alert(Wrong password) in IOS 8, keyboard opens automatically and hide the alert(just in Iphone 4s because of the screen's size), so I can't click in "OK" and I also can't dismiss keyboard because first I need to close the alert!
Keyboard hides alert
(It seems the app is recovering last keyboard's state and showing up again)
How can I close the keyboard before calling the alert?(this way the state will be "closed")
I've tried:
myTextField!.resignFirstResponder()
While calling the button, but it didn't work, the alert shows up and automatically the keyboard opens over it !
if myTextField!.resignFirstResponder() is not working properly try this when you present the alert before call this -->self.view.endEditing(true)
the above function is not work well , try
Choice -1 :Using the Responder Chain
UIApplication.sharedApplication().sendAction("resignFirstResponder", to:nil, from:nil, forEvent:nil)
This will resign the first responder (and dismiss the keyboard) every time, without you needing to send resignFirstResponder to the proper view. No matter what, this will dismiss the keyboard. It’s by far the best way to do it: no worrying about who the first responder is
Choice -2 :UIView’s endEditing
(assuming your text field is a subview of the view you call this on). Most of the time:
self.view.endEditing(true)
set Delegate to myTextField
Include
func textFieldShouldReturn(textField: UITextField) -> Bool
{
textField .resignFirstResponder()
return true
}
Other wise Try the following
var activeField : UITextField!
func textFieldDidBeginEditing(textField: UITextField)
{
activeField = textField
}
func textFieldDidEndEditing(textField: UITextField)
{
activeField = nil
}
func textFieldShouldReturn(textField: UITextField) -> Bool
{
textField .resignFirstResponder()
return true
}
Call activeField.resignFirstResponder() before alert appears
I think from iOS8 you need to use UIAlertController instead of UIAlertView. Using UiAlertView in iOS8 and above is causing keyboard to popup unnecessarily. I have seen this and i made a condition to use UIAlertController for iOS8 and above. In below version UIAlertView should work fine
This is UIAlertView bug on iOS 8.
I have same problem but UIAlertController has not problem. :3
UIAlertView was deprecated since iOS8.
https://developer.apple.com/reference/uikit/uialertview
In Swift 4 : below code worked for me
DispatchQueue.main.async() {
self.view.endEditing(true)
}

Tapping between UITextFields in iOS7

When a UITextField is selected and has a keyboard shown, if I tap other parts of the view the keyboard disappears.
If I tap another UITextField, the keyboard stays up, the first textfield is deselected, and nothing happens. Then I need to tap on the other UITextFIeld again for selection to happen and a keyboard to appear.
Is there a way to make a second UITextField immediately accessible when a first UITextField is selected?
If you reload the tableview in textFieldDidEndEditing, you'll break selection in this way. Don't do that.
try it, press another view should call below fn.
-(void)disappearKey{
[self.view endEditing:YES];
}
after keyboard disappear, Tap any textfield, will appear keyboard.
First of all I think its a bug that the keyboard is not dismissed and opened again when tapping on another UITextField or UITextView. It should be reported and Apple should fix it.
Using the textfield delegate methods and registering for keyboard notification it should be possible to manually keep track if the user tapped on another textfield and the keyboard did not close and reopen. At the very least you should be able to detect when this is happening and close the keyboard manually by [textField resignFirstResponder];
The keyboard notification are as follows:
UIKeyboardWillShowNotification
UIKeyboardDidShowNotification
UIKeyboardWillHideNotification
UIKeyboardDidHideNotification
I'm''pretty sure you know the UITextfield and textview delegate methods
– textFieldShouldBeginEditing:
– textFieldDidBeginEditing:
– textFieldShouldEndEditing:
– textFieldDidEndEditing:
I am not in an active project at the moment so I'm not sure if I just ignored the problem but I can't recall this happening to me.
you can use BSKeyboardControls. just see the demo and decide to
use or not.
or you can do you have to set tag in sequence to the each textfield
in uiview. then use the below code.
-(BOOL)textFieldShouldReturn:(UITextField*)textField
{
NSInteger nextTag = textField.tag + 1;
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder) {
[nextResponder becomeFirstResponder];
} else {
[textField resignFirstResponder];
}
return NO;
}

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;
}
}

Resources