我在我的应用程序中有一个UIDatePicker,虽然我更改模拟器中选择的日期,但当我NSLog输入datePicker.date
时,它输出当前日期比我选择的那个要好。UIDatePicker日期属性将不会设置所选日期 - 而是给出当前日期
这里是我的代码的提取物:(其中,产生拾取器)
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的输出总是当前DATE而不是在UIDatePicker中选择的日期。不知道这是为什么,因为从我所知道的情况来看,date
属性应该显示所选内容,而不是当前日期(或者在用户更改值之前最初选择的内容)。
任何帮助,将不胜感激。 (如果您需要更多信息,请通知我)。 谢谢!我敢肯定,它一定是我在仓促时忽略的东西。
嗨。谢谢你的帮助。我刚刚尝试过,结果和以前一样。然而,我找到了解决方案(请参阅我刚刚发布的答案),但对于正在发生的事情,它似乎仍然很不寻常。 – 2012-07-20 13:01:06