0

UIbuttonUIViewController. 单击它会打开一个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. 现在我必须更改设置或日期选择器吗?如果您需要更多信息,请询问。谢谢。

4

1 回答 1

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];

}

并在解雇行动的方法中。

-(void) Dismiss_Actionshit1
{
   // Your action sheet dismiss code
}
于 2013-01-18T07:15:17.623 回答