UIDatePicker 用法

 IOS UIDatePicker用法:

  

1 .h

@interface ViewController :UIViewController

{

  UILabel *datelabell;

  UIDatePicker *datepicker;

}

@property (nonatomic,retain) IBOutlet UILabel *datelabel;

@property (nomatomic,retain) IBOutlet UIDatePicker *datepicker;

-(IBAction) dateChange:(id)sender;

@end 

 

2. m

  a).@synthesize datelabel;

      @synthesize datepicker; 

  b). -(void) viewDidUnload

       {

           [super viewDidUnload];

           self.dateLabel=nil;

           self.datepicker=nil;

         }

  c). -(void) dealloc

      {

           [datelabel release];

           [datepicker release];

           [super dealloc];

      ] 

 

   d).  //get current system date

    NSDate *currdate=[datePicker date];

    NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];

    [dateFormatter setDateStyle:NSDateFormatterShortStyle];

    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];

    

    NSString *timeStr=[dateFormatter stringFromDate:currdate];

 

    dateLabel.text=[NSString stringWithFormat:@"Choose date is %@",timeStr];

    

    [dateFormatter release];

 

3 run reslut

 

posted @ 2012-07-04 18:37  大树2  阅读(517)  评论(0编辑  收藏  举报