我的UIbutton
上有一个UIViewController
。点击它会打开一个UIActionSheet
,其上有一个UIDatePicker
和一个关闭按钮。我将UIDatePicker
设置为日期模式。因此它显示今天的日期。假设我想选择2015而不是2013,我必须向下滚动。但它不允许我向下滚动。我必须向上滚动一次到2012,然后向下滚动。这似乎是一个小问题,但客户想要正确滚动。我检查了我的个人电话设置闹钟,我可以自由向下滚动。我不必向上滚动然后向下滚动。这就是按钮点击时发生的情况。
- (IBAction)btnShowDateNeededClick:(UIButton *)sender
{
UIDatePicker *datePickerView = [[UIDatePicker alloc]init];
datePickerView.datePickerMode = UIDatePickerModeTime;
self.actSheet = [[ UIActionSheet alloc]init];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blueColor];
closeButton.tag = 101;
[closeButton addTarget:self action:@selector(dismissActionSheetWithTime:) forControlEvents:UIControlEventValueChanged];
[self.actSheet addSubview:closeButton];
[self.actSheet showInView:self.view];
[self.actSheet addSubview:datePickerView];
[self.actSheet sendSubviewToBack:datePickerView];
[self.actSheet setBounds:CGRectMake(0, 0, 320, 500)];
}
如您所见,我有datePicker
段控件作为添加到UIActionsheet
的按钮。现在我必须更改设置或日期选择器吗?如果您需要更多信息,请询问。感谢。
答案 0 :(得分:1)
试试这个。可能是这个帮助。
在.h文件中。
UIDatePicker *datePickerView;
UIActionSheet *Actionsheet1;
在.m文件中
在viewDidLoad方法
中// Picker Initialization
datePickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 0, 0)];
datePickerView.datePickerMode = UIDatePickerModeDateAndTime;
创建一个将在按钮上单击
调用的函数-(void) Create_Start_Date_Picker_Function
{
Actionsheet1 = [[UIActionSheet alloc] initWithTitle:nil delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
Actionsheet1.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[Actionsheet1 addSubview: datePickerView];
[Actionsheet1 showInView:self.view];
[Actionsheet1 setBounds:CGRectMake(0, 0, 320, 485)];
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 blueColor];
[closeButton addTarget:self action:@selector(Dismiss_Actionshit1) forControlEvents:UIControlEventValueChanged];
[Actionsheet1 addSubview:closeButton];
}
用于解雇actionshit的方法。
-(void) Dismiss_Actionshit1
{
// Your action sheet dismiss code
}