-1

I'm trying to implement a UIDatePickeron Storyboard. As you would expect, the date picker can't be on screen when the view first loads so I have to write the custom code to move it off screen on load. Here's the code...

- (void)hideDatePicker
{
  CGRect newRect = self.datePicker.frame;
  CGPoint newOrigin = CGPointMake( 0, [[UIScreen mainScreen] bounds].size.height);
  newRect.origin = newOrigin;

  self.datePicker.frame = newRect;
}

I am currently calling this method in viewDidLoad.

When I run the app, the date picker is still on the bottom of the screen, disgustingly taking up half the screen...

2
  • What is self.datePicker when you do this. Maybe you forgot to link the picker to your code and self.datePicker == nil.
    – onevcat
    Dec 18, 2012 at 7:27
  • Do not call it in viewDid Load: if you want to load it later.Maybe call the method on a button action or hide it before and then make it unhidden.
    – Divya
    Dec 18, 2012 at 7:28

2 Answers 2

1

You may want to implement it inside an UIActionSheet, a not-so-difficult and elegant solution. Check out this question that will provide you a brief explanation and the necessary code. Add UIPickerView & a Button in Action sheet - How?

0
1

In -viewDidLoad: you can't be sure that all IBOutlets are instantiated and all geometry set, so you better call your method in -view[Will/Did]Appear: if you're using any geometry transformations. And it's easier to hide with hidden property

yourView.hidden = YES;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.