gpt4 book ai didi

iphone - 如何使用日期选择器在按钮上显示选定的日期?

转载 作者:行者123 更新时间:2023-11-28 22:50:12 26 4
gpt4 key购买 nike

当我点击我的按钮时,我能够成功地显示日期选择器。但是当我从日期选择器中选择日期时,我无法在 UIbutton 上显示所选日期。请帮助我

这是我的代码:

-(IBAction)btnDateClicked:(id)sender
{
UIActionSheet *actionSheet1 = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];

[actionSheet1 setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

CGRect pickerFrame = CGRectMake(0, 40, 0, 0);


UIDatePicker *pView=[[UIDatePicker alloc] initWithFrame:pickerFrame];

pView.datePickerMode=UIDatePickerModeDate;

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

[df setDateFormat:@"MM/dd/yyyy"];

// NSDate *date=[df dateFromString:self.hController.fromDateTime];

// [pView setDate:date animated:YES];

self.datePicker=pView;

[actionSheet1 addSubview:self.datePicker];

[pView release];

UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];

closeButton.momentary = YES;

closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);

closeButton.segmentedControlStyle = UISegmentedControlStyleBar;

closeButton.tintColor = [UIColor blackColor];

[closeButton addTarget:self action:@selector(dismissActionSheet1:) forControlEvents:UIControlEventValueChanged];

[actionSheet1 addSubview:closeButton];

[closeButton release];

[actionSheet1 showInView:[[UIApplication sharedApplication] keyWindow]];

[actionSheet1 setBounds:CGRectMake(0, 0, 320, 485)];

self.actionSheet=actionSheet1;

[actionSheet1 release];
}
///////////////////////////////////
- (void)dismissActionSheet1:(id)sender
{
[self.actionSheet dismissWithClickedButtonIndex:0 animated:YES];

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

[df setDateFormat:@"MM/dd/yyyy"];

//NSString *str=[df stringFromDate:self.datePicker.date];

//self.hController.selectDate=str;
}

最佳答案

将一些标签作为 subview 添加到显示点击事件选择器 View 的按钮。从日期选择器中选择日期时,将标签文本更新为所选日期

关于iphone - 如何使用日期选择器在按钮上显示选定的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12177261/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com