我正在使用Date選取器並且做得很好,但datepicker工具欄中DONE按鈕的操作不起作用。 請幫忙解決這個問題。UIBarbutton操作不與UIDatePicker一起工作
~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
- (IBAction)timepicker:(id)sender {
timepicker.hidden = NO;
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.timeStyle = NSDateFormatterShortStyle;
timebtn.titleLabel.text = [NSString stringWithFormat:@"%@",[df stringFromDate:timepicker.date]];
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleBlackOpaque;
toolbar.frame=CGRectMake(0,4,timepicker.frame.size.width,40);
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDoneClicked:)];
[toolbar setItems:[NSArray arrayWithObject:doneBtn] animated:NO];
[timepicker addSubview:toolbar];
}
- (IBAction)pickerDoneClicked:(id)sender
{
NSLog(@"DONE IS PRESSED");
[timepicker setHidden:YES];
}
請問我比「不工作」更具體嗎? –
代碼檢查正常。嘗試在方法和調試上都放置一個斷點。張貼更多的代碼片段。也許問題出在其他地方 – staticVoidMan
@staticVoidMan我也這樣做bt無法找到錯誤.... –