1.首先實現UIActionSheetDelete協議
2.
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:nil destructiveButtonTitle:nil otherButtonTitles:@"Set", nil];
[actionSheet showInView:self.view];
UIDatePicker *datePicker = [[[UIDatePicker alloc] init] autorelease];
datePicker.tag = 101;
// datePicker.datePickerMode = [(UISegmentedControl *)self.navigationItem.titleView selectedSegmentIndex];
[actionSheet addSubview:datePicker];
3.響應點擊 Set後的函數
//根據 buttonIndex的參數的不同,進行處理。
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIDatePicker *datePicker = (UIDatePicker *)[actionSheet viewWithTag:101];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
formatter.dateFormat = @"MM/dd/YY h:mm a";
NSString *timestamp = [formatter stringFromDate:datePicker.date];
//顯示時間的變數
[(UILabel *)[self.view viewWithTag:103] setText:timestamp];
[actionSheet release];
}