我见过这个 https://developer.apple.com/library/ios/samplecode/DateCell/Introduction/Intro.html(日期单元格)我的问题,但这是在这个例子中使用存储板,我不使用商店板。那么如何在我的视图控制器中执行此操作。
答案 0 :(得分:0)
使用此:
// 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
首先,在使用视图之前,使用initPickerView
方法在任何位置初始化选择器视图。然后,当您需要选择器视图时,请使用showPickerView
。并使用hidePickerView
将其从单元格中删除。