0
當您單擊dateTextField
,它顯示datePicker
與toolBar
。
我添加doneButton
到toolBar
,但doneButton
無法點擊。
我該如何解決?的UIBarButtonItem上的UIDatePicker作爲inputView不能點擊
@property (nonatomic, retain) UIDatePicker* datePicker;
@property (nonatomic, retain) UIToolBar* toolBar;
@property (nonatomic, retain) UITextField* dateTextField;
self.datePicker = [[UIDatePicker alloc]init];
self.datePicker.datePickerMode = UIDatePickerModeTime;
self.toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, -40, 320, 40)];
[self.datePicker addSubview:self.toolBar];
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(closePicker)];
NSArray* barItems = [NSArray arrayWithObjects:doneButton, nil];
[self.toolBar setItems:barItems animated:YES];
self.dateTextField = [[UITextField alloc]initWithFrame:CGRectMake(90, 5, 100, 25)];
self.dateTextField.delegate = self;
self.dateTextField.inputView = self.datePicker;
[self.view addSubview:self.dateTextField];
謝謝。