I have a UITextField set as a DataEntry cell in my table, and I have 2 Tabs at the bottom of my View.
I have set placeholder text in my Text field “Reference Information” which is perfectly acceptable for the user to not enter anything. BUT
If they click that field and then don’t enter anything, they are unable to actually dismiss the keyboard unless they leave the screen.
Is there a way to hide the keyboard Or make “DONE” always available even if they have no text entered in the field?
I believe I have dealt with the Clear Button, and Backspacing out any entered text, I just can’t get the Nothing done dismissal.
I don’t like using the Timer to clear/dismiss and if I can find an answer to this I will remove that.
-(BOOL)textFieldShouldClear:(UITextField *)textField
{
NSLog(@"should clear");
[NSTimer scheduledTimerWithTimeInterval:0.01
target:self selector:@selector(dismiss)
userInfo:nil repeats:NO] ;
return YES;
}
-(void)dismiss
{
[_referenceText resignFirstResponder];
}
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:
(NSRange)range replacementString:(NSString *)string
{
if(textField.text.length == 1 && string.length==0)
{
textField.text = @"";
[textField resignFirstResponder];
}
// NSLog(@"Orig - %@ New - %@", textField.text , string);
return YES;
}
For reference you need to turn off the “Auto Enable Return Key”
Seems so simple, but devilishy hidden.