我的应用程序中有一个 UIDatePicker,虽然我更改了在模拟器中选择的日期,但是当我 NSLog 时datePicker.date
,它会输出当前日期而不是我选择的日期。
这是我的代码的摘录:(生成选择器的位置)
self.pickerView = [[UIDatePicker alloc] initWithFrame:pickerFrame];
//self.pickerView.frame = pickerFrame;
self.pickerView.datePickerMode = UIDatePickerModeDate;
actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[actionSheet addSubview:pickerView];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventValueChanged];
[pickerView addTarget:self action:@selector(pickerChange) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];
[actionSheet setBounds:CGRectMake(0, 0, 320, 251)];
pickerView.maximumDate = [NSDate dateWithTimeIntervalSinceNow:315360000];
pickerView.minimumDate = [NSDate dateWithTimeIntervalSinceNow:-315360000];
然后在我的pickerChange函数中:
-(void)pickerChange{
NSLog(@"DEBUG: Picker Value Changed");
NSLog(@"%@",self.pickerView.date );
}
该 NSLog 的输出始终是当前日期,而不是在 UIDatePicker 中选择的日期。不知道为什么会这样,因为据我所知,该date
属性应该显示选择的内容,而不是当前日期(或在用户更改值之前最初选择的内容)。
任何帮助,将不胜感激。(如果您需要更多信息,请给我留言)。谢谢!我敢肯定,这一定是我在匆忙中忽略了的东西。