-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...

brianSan
  • 545
  • 6
  • 17
  • 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 '12 at 07: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 '12 at 07:28

2 Answers2

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;

ksh
  • 1,894
  • 19
  • 20
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?

Community
  • 1
  • 1
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235