我是iPhone開發新手。選擇文本字段時,我想添加UIDatePicker
。 兩個日期選擇器在那裏。在iOS應用程序中的日期選擇器
- (void)textFieldDidBeginEditing:(UITextField *)aTextField
{
[aTextField resignFirstResponder];
pickerViewPopup = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 0, 0)];
pickerView.datePickerMode = UIDatePickerModeDate;
pickerView.hidden = NO;
pickerView.date = [NSDate date];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
[barItems addObject:doneBtn];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
[barItems addObject:cancelBtn];
[pickerToolbar setItems:barItems animated:YES];
[pickerViewPopup addSubview:pickerToolbar];
[pickerViewPopup addSubview:pickerView];
[pickerViewPopup showInView:self.view];
[pickerViewPopup setBounds:CGRectMake(0,0,320, 464)];
}
我用這個,但得到了兩個不同的日期選擇器相同的值。我想,如果我按textfield1然後datepicker打開並保存該值的文本字段之一和第二個文本相同。謝謝。
謝謝你的回答,但我仍然無法做到這一點..請檢查該代碼 - (void)doneButtonPressed:(id)sender { //在這裏做一些事情,用[picke rView date]獲取該值 [pickerViewPopup dismissWithClickedButtonIndex:1 animated:YES]; } - (無效)cancelButtonPressed:(ID)發送方 { [pickerViewPopup dismissWithClickedButtonIndex:1動畫:YES]; } –
@MaulikVekariya檢查出我在這篇文章中的答案http://stackoverflow.com/questions/3624013/adding-a-button-to-uidatepicker/3624329#3624329 –
仍然我沒有得到ny輸出我得到那個當我觸摸textfield1然後datepicker打開這是最好的,但是當我選擇日期,然後按完成,然後在textfield1和textfield2中打印thi s值我都希望這兩個值sepretely..plz幫助我bhai ... –