使用UIActionSheet 弹出UIDatePicker

来源:互联网 发布:淘宝网男士长袖衬衣 编辑:程序博客网 时间:2024/05/18 02:32
-(IBAction)SelectValue:(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:title delegate:self cancelButtonTitle:@"确定" destructiveButtonTitle:nil otherButtonTitles:nil];
    
    

    
    [actionSheet showInView:self.view];
    UIDatePicker *datePicker = [[[UIDatePicker alloc] init] autorelease];
    datePicker.tag = 101;
    datePicker.datePickerMode = 1;
    [actionSheet addSubview:datePicker];
  
     [actionSheet showFromTabBar:(UITabBar *)self.tabBarController.view];     
    
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    UIDatePicker *datePicker = (UIDatePicker *)[actionSheet viewWithTag:101];
    NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
    formatter.dateFormat = @"yyyy年 MM月 dd日";
    NSString *timesp = [formatter stringFromDate:datePicker.date];
    TradedateLabel.text =timesp;
    [actionSheet release];
}


原创粉丝点击