- (IBAction)getDate:(id)sender { NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en-US"] autorelease]; NSDate *pickerDate = [datePicker date]; NSString *sel = [[NSString alloc] initWithFormat:@"%@", [pickerDate descriptionWithLocale:usLocale]]; lblResult.text = sel; [sel release]; }
// // ViewController.h // datePickerApp // // Created by Weerachai on 11/10/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController { IBOutlet UIDatePicker *datePicker; IBOutlet UILabel *lblResult; } - (IBAction)getDate:(id)sender; @end
// // ViewController.m // datePickerApp // // Created by Weerachai on 11/10/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)getDate:(id)sender { NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en-US"] autorelease]; NSDate *pickerDate = [datePicker date]; NSString *sel = [[NSString alloc] initWithFormat:@"%@", [pickerDate descriptionWithLocale:usLocale]]; lblResult.text = sel; [sel release]; } - (void)dealloc { [datePicker release]; [lblResult release]; [super dealloc]; } @end
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท