How to disable a button after entering a particular letter in a textfield?
+2
A:
Bind the text field's value to one of your object's properties and ensure to check the "updates continuously" box in Interface Builder. For this example, the property will be called theText
. Then, bind the enabled state of the button using a key-value path of say containsLetterA
, then in your object put the method
- (BOOL) containsLetterA
{
NSRange rangeOfLetterA = [[self theText] rangeOfString:@"A"];
return rangeOfLetterA.location != NSNotFound;
}
Then, also in your object, add the class method:
+ (NSSet *) keyPathsForValuesAffectingValueForContainsLetterA
{
return [NSSet setWithObjects:@"theText", nil];
}
dreamlax
2009-08-26 11:50:57