0

UIPickerView の選択と非表示

これを使用して、テキスト フィールドを「タッチダウン」したときに日付ピッカー ビューをポップアップ表示しました。つまり、日付ピッカー ビューで選択したものを内容として表示するには、テキスト フィールドが必要です。

 - (IBAction)showPicker:(id)sender {

    // create a UIPicker view as a custom keyboard view
    UIDatePicker* pickerView = [[UIDatePicker alloc] init];
    [pickerView sizeToFit];
    pickerView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    //pickerView.delegate = self;
    //pickerView.dataSource = self;
    //pickerView.showsSelectionIndicator = YES;
    self.datePickerView = pickerView;  //UIDatePicker



    fromDate.inputView = pickerView;



    // create a done view + done button, attach to it a doneClicked action, and place it in a toolbar as an accessory input view...
    // Prepare done button
    UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
    keyboardDoneButtonView.barStyle = UIBarStyleBlack;
    keyboardDoneButtonView.translucent = YES;
    keyboardDoneButtonView.tintColor = nil;
    [keyboardDoneButtonView sizeToFit];

    UIBarButtonItem* doneButton = [[[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                                    style:UIBarButtonItemStyleBordered target:self
                                                                   action:@selector(pickerDoneClicked:)] autorelease];

    fromDate.text = (NSString *)datePickerView.date; // fromDate is the Text Field outlet, where I am trying to display the selection on the picker.

    [keyboardDoneButtonView setItems:[NSArray arrayWithObjects:doneButton, nil]];

    // Plug the keyboardDoneButtonView into the text field...
    fromDate.inputAccessoryView = keyboardDoneButtonView;  

    [pickerView release];
    [keyboardDoneButtonView release];
     }

    - (IBAction)pickerDoneClicked:(id)sender {

        [fromDate resignFirstResponder];
    }

編集:画面上の1つのテキストフィールドに対してこれを行うことができます。何があっても、2 番目のテキスト フィールドにはキーボードだけが表示されます。

2番目のテキストフィールドでこれを行うアイデアはありますか?

4

2 に答える 2

0

あなたの問題に対するただの代替解決策。

UIButton1)表示したいタップのテキストフィールドにカスタムを置きますUIDatePickerView

2)ピッカービューを表示するテキストフィールドのデリゲートをnilに設定します。

fromDate.delegate = nil;

3)IBActionそのカスタムボタンの(「タッチダウン」)に以下のコードを書きます:-

- (IBAction) customButtonAction: (id) sender
{
    [_previousTextField resignFirstResponder]; // The instance of last textfield tapped.

    [self showDatePicker];
}

4)ピッカービューの[完了]ボタンをタップして、選択した値をテキストフィールドに設定します

- (IBAction)pickerDoneClicked:(id)sender 
   {
      fromDate.text = @"value from UIPickerView's selected row"
   }
于 2012-07-17T11:50:49.567 に答える
0
fromDate.inputView = pickerView;

このコード行は、ピッカー ビューを fromDate フィールドの入力ビューにします。他の日付フィールドにも同様のコードが必要です。また、他のフィールドに入力アクセサリを設定する必要があります。

これを行うための特別なメソッドを作成し、すべてのテキスト フィールドにアクションを追加するのは不要な作業です。でピッカー ビューとツールバーを作成し、viewDidLoad必要なフィールドの入力ビューとアクセサリ ビューに割り当てるだけです。テキスト フィールドには、キーボードを表示する touch down メソッドが既にあります。

于 2012-07-17T10:49:06.017 に答える