jfalexvijay
jfalexvijay

Reputation: 3711

how to disable a button dynamically

How to disable a button after entering a particular letter in a textfield?

Upvotes: 0

Views: 798

Answers (1)

dreamlax
dreamlax

Reputation: 95315

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

Upvotes: 2

Related Questions