0

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

1 Answer 1

2

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];
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.