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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top