0
UIPickerView select and hideiPhone應用:日期選取器查看下拉列表
我用這個彈出日期選擇器視圖上的文本字段,當我「降落」。也就是說,我需要文本字段來顯示我在日期選擇器視圖上選擇的內容作爲其內容。
一旦我選擇所需的日期/時間後點擊「完成」按鈕,文本字段不顯示我的輸入。
我錯過了什麼?
- (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];
}
設置選擇你實現什麼選擇器視圖的委託方法? – jrturton 2012-07-17 07:44:55
我正要插入代碼時,我不小心打進入和問題得到公佈。 – esh 2012-07-17 07:50:50