0

I have seen this https://developer.apple.com/library/ios/samplecode/DateCell/Introduction/Intro.html (Date Cell) for my question but this is use Store board in this example and I am not use store board. so how can do this in my view controller.

Rahul Sharma
  • 940
  • 2
  • 12
  • 31
  • Have you searched SO or Google for help ? Check [this](http://stackoverflow.com/questions/18973573/ios-7-how-to-display-a-date-picker-in-place-in-a-table-view) and [this](http://stackoverflow.com/questions/17775913/how-to-show-uidatepicker-from-uitableviewcell) first. – n00bProgrammer Mar 29 '14 at 06:38
  • The apple code is horrible. This project displays date picker without storyboard https://github.com/ajaygautam/DateCellWithoutStoryboard – Anirudha Agashe Jul 28 '14 at 05:30

1 Answers1

0

Use this:

// Cell.m

@interface Cell ()

@property (strong, nonatomic) UIPickerView *pickerView;

@end    

@implementation

- (void)initPickerView {
    _pickerView = [[UIPickerView alloc] init];
}

- (void)showPickerView {
    CGRect pickerViewFrame = _pickerView.frame;
    pickerViewFrame.origin.y = self.frame.size.height;
    _pickerView.frame = pickerViewFrame;

    [self addSubview:_pickerView];

    CGRect cellFrame = self.frame;
    cellFrame.size.height += pickerViewFrame.size.height;
    self.frame = cellFrame;
}

- (void)hidePickerView {
    CGRect cellFrame = self.frame;
    cellFrame.size.height -= _pickerView.frame.size.height;
    self.frame = cellFrame;

    [_pickerView removeFromSuperview];
}

@end

First of all, initialize picker view with initPickerView method in any place before using the view. Then, when you need picker view to appear use showPickerView. And use hidePickerView to remove it from the cell.

Igor Matyushkin
  • 778
  • 4
  • 4