简体   繁体   English

如何在iOS的表格单元中显示日期选择器和选择器视图?

[英]How to display date picker and picker view in table cell in iOS?

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. 对于我的问题,我已经看到了这个https://developer.apple.com/library/ios/samplecode/DateCell/Introduction/Intro.html (日期单元),但这是在此示例中使用存储板,而不是使用存储板。 so how can do this in my view controller. 所以如何在我的视图控制器中做到这一点。

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. 首先,在使用视图之前,请在任何地方使用initPickerView方法初始化选择器视图。 Then, when you need picker view to appear use showPickerView . 然后,当您需要显示选择器视图时,请使用showPickerView And use hidePickerView to remove it from the cell. 并使用hidePickerView将其从单元格中删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM