RookieAppler
RookieAppler

Reputation: 1545

UIdate picker does not move freely

I have a UIbutton on my UIViewController. Clicking that opens up an UIActionSheet with a UIDatePicker on it and a close button. I set the UIDatePicker to date mode .So it shows up with todays date. Suppose i want to select 2015 instead of 2013, i have to scroll down. But it won't allow me to scroll down. I have to scroll up once to 2012 and then scroll down. This seems like a minor issue but the client wants to scroll properly down. I checked on my personal phone to set alarm, i can freely scroll down. I don't have to scroll up and then scroll down. So this is what happens on button click.

- (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)];
}

As you see, i have datePicker, segment control as a button added to UIActionsheet. Now do i have to change settings or date picker? If you need more information, please ask. Thanks.

Upvotes: 0

Views: 128

Answers (1)

Wolverine
Wolverine

Reputation: 4329

Try This. may be this help.

In .h File.

UIDatePicker *datePickerView;
UIActionSheet *Actionsheet1;

In .m File

In viewDidLoad Method

// Picker Initialization

datePickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 0, 0)];
datePickerView.datePickerMode = UIDatePickerModeDateAndTime;

Make a function which will be called on your Button click

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

}

And in method for dismiss actionshit.

-(void) Dismiss_Actionshit1
{
   // Your action sheet dismiss code
}

Upvotes: 1

Related Questions