UIDatePickerView工作正常。它顯示,我可以滾動瀏覽日期,但由於某些原因,我選定的OB.text不斷出現,因爲今天的日期!無論我選擇什麼日期,它顯示爲今天的日期!UIDatePicker選擇日期不出現
我選擇這樣的:
的NSLog和標籤顯示爲:
下面是代碼:
- (IBAction)selectDOB:(id)sender
{
UIActionSheet *selectBirthMY = [[UIActionSheet alloc] initWithTitle:@"Select Date of Birth" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Select", nil];
[selectBirthMY setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[selectBirthMY showInView:[UIApplication sharedApplication].keyWindow];
[selectBirthMY setFrame:CGRectMake(0, 100, 320, 500)];
}
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 320, 216)];
pickerView.datePickerMode = UIDatePickerModeDate;
[pickerView setMinuteInterval:15];
//Add picker to action sheet
[actionSheet addSubview:pickerView];
//Gets an array af all of the subviews of our actionSheet
NSArray *subviews = [actionSheet subviews];
[[subviews objectAtIndex:1] setFrame:CGRectMake(20, 265, 280, 46)];
[[subviews objectAtIndex:2] setFrame:CGRectMake(20, 317, 280, 46)];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIDatePicker *DOBPicker = [[UIDatePicker alloc] init];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMMM dd, YYYY"];
NSDate *pickedDOB = [DOBPicker date];
NSString *DOB = [dateFormatter stringFromDate:pickedDOB];
NSLog (@"This is DOB %@", DOB);
self.selectedDOB.text=DOB;
}