UIDatePickerView は正常に動作しています。表示され、日付をスクロールできますが、何らかの理由で、選択したOB.textが今日の日付として表示され続けます! どの日付を選択しても、今日の日付として表示されます。
私はこれを選択します:
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;
}