gpt4 book ai didi

ios - iOS的UIDatePicker点击done但值没有变化,触发的事件是什么?

转载 作者:行者123 更新时间:2023-11-28 22:49:52 24 4
gpt4 key购买 nike

我在我的 iPhone 项目中使用 UIDatePicker。我想在打开它并单击“完成”按钮后在日期选择器中显示日期。我正在使用这段代码:

[datePicker addTarget:self action:@selector(changeDate:) forControlEvents:UIControlEventValueChanged]

changeDate 是我在别处定义的一个方法,我把 UIControlEventValueChanged 的​​相应代码放在那个方法中。但是,即使我没有进行任何更改,我也想在点击“完成”按钮后显示 UIDatePicker 中的值。我该怎么做?

最佳答案

您可以使用以下代码....

-(void)showDate{
menu = [[UIActionSheet alloc] initWithTitle:@"Select Date"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];

datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
datePicker.datePickerMode = UIDatePickerModeDate;
datePicker.minimumDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]autorelease]];
[dateFormatter setDateFormat:@"dd MMM yyyy"];
//[dateFormatter setDateFormat:@"MM/dd/YYYY"];

//[theDatePicker release];
[datePicker addTarget:self action:@selector(LabelChange:) forControlEvents:UIControlEventValueChanged];


dateTool = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
dateTool.barStyle=UIBarStyleBlackOpaque;
[dateTool sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(DatePickerDoneClick)];
[barItems addObject:flexSpace];

[dateTool setItems:barItems animated:YES];
[menu addSubview:dateTool];
[menu addSubview:datePicker];
[menu showInView:self.view];
[menu setBounds:CGRectMake(0,0,320, 464)];


// [self.view addSubview:datePicker];

[datePicker release];
}
-(IBAction)DatePickerDoneClick{
[menu dismissWithClickedButtonIndex:0 animated:YES];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{

return [arrTime count];

}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{

return [arrTime objectAtIndex:row];

}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

txtTime.text = [arrTime objectAtIndex:row];

}

关于ios - iOS的UIDatePicker点击done但值没有变化,触发的事件是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12274936/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com