我有一个 UIDatePicker,我想在 UIButton Click 上隐藏和显示。
为此,我使用 BOOL 变量 isTouchFirst。但它会在按钮的第二个事件中隐藏和显示。
请解决此问题。并首先检查它是否适用于双击事件。
if(isTouchFirst){
isTouchFirst=NO;
self. DatePicker.hidden=NO;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat"yyyy-MM-dd"];
_DatePicker.datePickerMode = UIDatePickerModeDate;
formatedDate=[[NSString alloc]init];
formatedDate = [dateFormatter stringFromDate:self.DatePicker.date];
self.SelectedDate.text =formatedDate;
[DatePicker setMinimumDate: [NSDate date]];
_goDateForcustmoeDetail=formatedDate;
}
else {
isTouchFirst=YES;
self. DatePicker.hidden=YES;
}
Best Answer-推荐答案 strong>
BOOL datePickerHidden;
- (void)viewDidLoad
{
[super viewDidLoad];
datePickerHidden = YES;
// _datePicker = [UIDatePicker alloc...
[_datePicker setHidden: datePickerHidden];
// UIButton *dateHiddenSwitchBtn = [UIButton alloc...
dateHiddenSwitchBtn addTarget:self actionselector(switchDatePickerHidden) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:dateHiddenSwitchBtn];
}
- (void)switchDatePickerHidden
{
if (datePickerHidden) datePickerHidden = NO;
else datePickerHidden = YES;
[_datePicker setHidden: datePickerHidden];
}
关于ios - 如何在按钮单击时隐藏/显示日期选择器?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/33450255/
|