1

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.

Michael Smith
  • 498
  • 2
  • 5
  • 15

1 Answers1

7

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.

El Developer
  • 3,345
  • 1
  • 21
  • 40
  • Oh, Do I feel like an idiot. I done this in viewDidLoad I am assuming that is wrong even though it works now. Thanks EDIT: Just read what you added makes alot more sense now. I feel even more stupid. You're the man. – Michael Smith Nov 25 '11 at 01:42
  • you have to call this function in viewDidLoad. dont call it in init functions. – Adem May 12 '14 at 10:31