title: How to design an iOS program with custom inputViews
body: <p>Note, this is a DESIGN question, NOT a functionality question.  I already know how to implement the following, I'm just trying to figure out the best way to design it.</p>
  
  <p>I have an iOS app where a few <code>UIViewControllers</code> throughout the app have <code>UITextFields</code> with <code>UIDatePicker</code> input views.  The code for this is below:</p>
  
  <pre><code>- (void) viewDidLoad
  {
      self.dateField.inputView = [self createDatePicker];
  }
  
  - (UIView *) createDatePicker
  {
      UIView *pickerView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, TOOLBAR_HEIGHT + KEYBOARD_HEIGHT)];
  
      UIDatePicker *picker = [[UIDatePicker alloc] init];
      [picker sizeToFit];
      picker.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
      picker.datePickerMode = UIDatePickerModeDate;
      [picker addTarget:self action:@selector(updateDateField:) forControlEvents:UIControlEventValueChanged];
      [pickerView addSubview:picker];
  
  
      // Create done button
      UIToolbar* toolBar = [[UIToolbar alloc] init];
      toolBar.barStyle = UIBarStyleBlackTranslucent;
      toolBar.translucent = YES;
      toolBar.tintColor = nil;
      [toolBar sizeToFit];
  
      UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
      UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                                     style:UIBarButtonItemStyleDone target:self
                                                                    action:@selector(doneUsingPicker)];
  
      [toolBar setItems:[NSArray arrayWithObjects:flexibleSpace, doneButton, nil]];
      [pickerView addSubview:toolBar];
      picker.frame = CGRectMake(0, toolBar.frame.size.height, self.view.frame.size.width, pickerView.frame.size.height - TOOLBAR_HEIGHT);
      toolBar.frame = CGRectMake(0, 0, self.view.frame.size.width, TOOLBAR_HEIGHT);
      return pickerView;
  }
  
  - (void) doneUsingPicker
  {
      [self.dateField resignFirstResponder];
  }
  
  
  - (void) updateDateField: (UIDatePicker *) datePicker
  {
      self.dateField.text = [self.formatter stringFromDate:datePicker.date];
  }
  </code></pre>
  
  <p>The problem is, I keep on having to paste this code throughout the app in different classes that have UITextFields with UIDatePicker inputviews.  What would be the best way to design this so as to minimize duplicated code.  I've thought about having a <code>UIDatePickerableViewController</code> superclass that contains this code, but this doesn't seem extensible.  For instance, what if I soon have other types of input views that could be attached to text fields.  How should I design this? </p>