Note that there are some explanatory texts on larger screens.

plurals
  1. POUITextFieldDelegate, checking if textFields have text in it
    text
    copied!<p>i have a little problem. There are two textFields in my TableView which set the property of an object. In order to do so i want to force the user to write something in the textField before the string is actually been set to the object. So basically a simple <code>([textField.text length] &gt; 0)</code> thing. But i want that the user have to write strings in both the two textFields to finally enable the "Done"-Button. I solved this earlier but with only one text Field with the following <code>UITextFieldDelegate</code> method.</p> <pre><code>- (BOOL)textField:(UITextField *)theTextField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString *newText = [theTextField.text stringByReplacingCharactersInRange:range withString:string]; self.doneBarButton.enabled = ([newText length] &gt; 0); return YES; } </code></pre> <p>My solution for the new problem, so now with two textFields is this one:</p> <pre><code>- (BOOL)textField:(UITextField *)theTextField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString *newText = [theTextField.text stringByReplacingCharactersInRange:range withString:string]; if ([theTextField.placeholder isEqualToString:@"textField1"]) { if ([theTextField.text length] &gt; 0) { enabledVokabel = YES; } else { enabledVokabel = NO; } } if ([theTextField.placeholder isEqualToString:@"textField2"]) { if ([theTextField.text length] &gt; 0) { enabledUebersetung = YES; } else { enabledUebersetung = NO; } } self.doneBarButton.enabled = (enabledVokabel &amp;&amp; enabledUebersetung); return YES; } </code></pre> <p>So i want the doneBarButton been enabled when both of the textFields (textField1 and textField2) are filled with text. But i want it that way that if the user has deleted the text he/she just wrote in the doneBarButton is disabled as soon as the textFields are empty. It doesn't work that way. Do you have a solution? Or maybe a better way to solve it?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload