Xcode Économie UIDatepicker pour les afficher dans un label

Le code suivant est de montrer mon UIDatepicker:

- (IBAction)showActionSheet:(id)sender {
    NSString *title = UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) ? @"\n\n\n\n\n\n\n\n\n" : @"\n\n\n\n\n\n\n\n\n\n\n\n" ;
    UIActionSheet *actionSheet = [[UIActionSheet alloc] 
                                  initWithTitle:[NSString stringWithFormat:@"%@%@", title, NSLocalizedString(@"Please Select A Date", @"")]
                                  delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"I've Made My Choice", nil];
    [actionSheet showInView:self.view];
    UIDatePicker *datePicker = [[[UIDatePicker alloc] init] autorelease];
    datePicker.datePickerMode = UIDatePickerModeDate;
    [actionSheet addSubview:datePicker];
}

Tout fonctionne correctement, mais ce que je voudrais faire est d'afficher les utilisateurs de choix dans une étiquette que j'ai nommé " label1 ". Quelqu'un peut-il aider? Merci!

Mise à JOUR:

Voici le code mis à jour:

- (IBAction)showActionSheet:(id)sender {
NSString *title = UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) ? @"\n\n\n\n\n\n\n\n\n" : @"\n\n\n\n\n\n\n\n\n\n\n\n" ;
UIActionSheet *actionSheet = [[UIActionSheet alloc] 
                              initWithTitle:[NSString stringWithFormat:@"%@%@", title, NSLocalizedString(@"Please Select A Date", @"")]
                              delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"I've Made My Choice", nil];
[actionSheet showInView:self.view];
UIDatePicker *datePicker = [[[UIDatePicker alloc] init] autorelease];
datePicker.datePickerMode = UIDatePickerModeDate;
[actionSheet addSubview:datePicker];
[datePicker addTarget:self
               action:@selector(updateLabel:)
     forControlEvents:UIControlEventValueChanged];  

}

- (void)updateLabel:(id)sender {
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;
label1.text = [NSString stringWithFormat:@"%@",[df stringFromDate:datePicker.date]];
[df release];


/* the following allows you to choose the date components
 NSCalendar *calendar = [NSCalendar currentCalendar];

 int hour   =    [[calendar components:NSHourCalendarUnit    fromDate:[datePicker date]] hour];
 int minute =    [[calendar components:NSMinuteCalendarUnit  fromDate:[datePicker date]] minute];

 int year   =    [[calendar components:NSYearCalendarUnit    fromDate:[datePicker date]] year];
 int month  =    [[calendar components:NSMonthCalendarUnit   fromDate:[datePicker date]] month];
 int day    =    [[calendar components:NSDayCalendarUnit     fromDate:[datePicker date]] day];
 */

}

C'est pour la .m , mon .xib a 'label' attaché correctement aussi 🙂 juste faire un (null) valeur à chaque fois que je choisir ma date 🙁

InformationsquelleAutor Macfan9000 | 2011-01-30