Skip to main content

Posts

Showing posts with the label textfield

xcode 4.2.1 - limiting character length in TextField

I have been trying to limit a textField by many codes available out there in the internet but with no luck. I have added UIViewController<UITextFieldDelegate> in my header file and textField.delegate = self; in my viewDidLoad and implemented the following fundtion in my .m file: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string]; return !([newString length] > 5); } this stil does not limit my text field. any idea?