Search code examples
iphoneobjective-cxcodeuitextfielduitextfielddelegate

UITextField doesn't seem to be calling textFieldShouldBeginEditing


I am trying to disable UITextField from opening the keyboard but I am having trouble

.h

#import <UIKit/UIKit.h>
@interface XXViewController : UIViewController <UITextFieldDelegate> {
    IBOutlet UITextField* someTextField;
}

@property (nonatomic, retain) IBOutlet UITextField* someTextField;
@end

.m

@implementation XXViewController

@synthesize someTextField;


-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    NSLog(@"Hello");
    return NO;  
}
...

I am sure this is a very simple problem. I have been searching for ages and couldn't find a solution

Thanks Advance

EDIT: NSLog isn't being called.


Solution

  • You need to do:

    [someTextField setDelegate:self];
    

    Because although your class can be a delegate you never set it as the delegate for the UITextField you are using.