これはデザインの問題であり、機能の問題ではないことに注意してください。以下を実装する方法はすでに知っています。それを設計するための最良の方法を見つけようとしています。
UIViewControllersアプリ全体のいくつかUITextFieldsにUIDatePicker入力ビューがある iOS アプリがあります。このコードは以下のとおりです。
- (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];
}
問題は、UITextFields と UIDatePicker inputviews を持つさまざまなクラスのアプリ全体にこのコードを貼り付けなければならないことです。重複コードを最小限に抑えるためにこれを設計する最良の方法は何でしょうか。このコードを含むスーパークラスを持つことを考えましたUIDatePickerableViewControllerが、これは拡張可能ではないようです。たとえば、テキスト フィールドにアタッチできる他の種類の入力ビューがすぐにあるとしたらどうでしょう。これをどのように設計すればよいですか?