我是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 ... –