现在介绍第二种时间选择器,原帖在哪里看我找不到了,自己写这个教程。。。
在头文件中声明
IBOutlet UIDatePicker *datePicker;
@property (nonatomic,retain) UIDatePicker *datePicker;
在类中实现
@synthesize datePicker;
在要触发的按钮事件写如下代码:
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:title
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles:@"确定", nil];
[actionSheet showInView:self.view];
datePicker = [[[UIDatePicker alloc] init] autorelease];
datePicker.tag = 101;
datePicker.datePickerMode = UIDatePickerModeDate;
[actionSheet addSubview:datePicker];
然后实现点击事件
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex==0) {
UIDatePicker *datePicker0= (UIDatePicker *)[actionSheet viewWithTag:101];
NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
formatter.dateFormat = @"MM-dd-YY";
NSString *timestamp = [formatter stringFromDate:datePicker0.date];
/*在此处加入你需要实现的功能代码*/
}
}
下一个datepicker教程,将自己实现一个datepicker,利用alertview