Search code examples
iphonexcodeuitextfielduitextfielddelegate

How to make a UITextField not respond?


I want to make a UITextField so that when I touch it, it runs a certain method, then if the conditions are correct (which are tested within that method), it will run its normal 'bring up the keyboard' method. How can I do this?


Solution

  • Set a delegate for your UITextField

    textField.delegate = self;
    

    Then within the delegate, implement:

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
        if (condition) {
            return YES;
        }
        else {
            return NO;
        }
    }