0
這似乎很奇怪......我在actionSheet中使用UidatePicker。點擊一個按鈕我顯示行動表。當我選擇2012年12月31日的日期並點擊完成時,我收到的日期是2013年12月31日。這是發生在所有年份並且僅在12月31日。我做錯了什麼嗎?這裏是我的代碼12月31日UIDatePicker問題
-(void)dateButtonPressed:(id)sender //Method invoking the action sheet on button press
{
actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
closingdatePicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
closingdatePicker.tag=10;
closingdatePicker.datePickerMode=UIDatePickerModeDate;
pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle = UIBarStyleBlackTranslucent;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(DatePickerCancelClick:)];
[barItems addObject:cancelBtn];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(DatePickerDoneClick:)];
[barItems addObject:doneBtn];
[pickerToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerToolbar];
[actionSheet addSubview:closingdatePicker];
[actionSheet showInView:self.view];
[closingdatePicker release];
[actionSheet setBounds:CGRectMake(0,0,320, 464)];
[actionSheet release];
}
- (void)DatePickerDoneClick:(id)sender{ //doen click and my date is stored in selectedDate
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/YYYY"];
//Gets our picker
UIDatePicker *ourDatePicker = (UIDatePicker *) [actionSheet viewWithTag:10];
NSDate *selectedDate = [ourDatePicker date];
closingDate.text=[NSString stringWithFormat:@"%@",[formatter stringFromDate:selectedDate]];
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
燁解決...... :)但它是如何影響 – southpark 2012-04-13 10:42:04