title: How to set delegate of text field in Objective-C?
body: <p>I'd like to customize a <code>UITextField</code> by limiting it to four chars. I'm trying to understand how delegates work in <code>Objective-C</code> and have gone through the following steps to implement this functionality, still with no luck getting a working solution.</p>
  
  <p>1) Created a LimitedLengthTextField objective-c class. Made the class of type <code>UITextField</code> and accept objects of type &lt; UITextFieldDelegate >.</p>
  
  <p>LimitedLengthTextField.h:</p>
  
  <pre><code>@interface LimitedLengthTextField : UITextField &lt;UITextFieldDelegate&gt;
  @end
  </code></pre>
  
  <p>2) Implemented the following method in LimitedLengthTextField.m:</p>
  
  <pre><code>@implementation LimitedLengthTextField
  
  - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
      NSUInteger newLength = [textField.text length] + [string length] - range.length;
      return (newLength &gt; 4) ? NO : YES;
  }
  
  @end
  </code></pre>
  
  <p>3) Imported "LimitedLengthTextField.h" in my CreateAccount class and tried to set the delegate of the UITextField "ssnTextField" in <code>viewDidLoad</code> as follows (my app accepts the last 4 digits of the user's SSN). </p>
  
  <pre><code>// Set the custom SSN textfield delegate
  LimitedLengthTextField *custTextField = [[LimitedLengthTextField alloc] init];
  [self.ssnTextField setDelegate:custTextField];
  </code></pre>
  
  <p>Based on my limited understanding of <code>Objective-C</code> and delegates, I've now created a class, implemented the delegate method I want, then created an instance of that class and assigned it to my UITextView object. What am I missing?</p>