2018/4/9更新
增加自定义cell接口,对原先函数命名方式调整,一些bug修改
使用方式和使用picker view相似:
1、创建TablePickerView:
- (instancetype)initWithFrame:(CGRect)frame delegate:(id<TablePickerViewDataSource,TablePickerViewDelegate>)delegate;
2、实现数据源代理TablePickerViewDataSource:
@optional
- (NSInteger)numberOfComponentsInTablePickerView:(TablePickerView *)tablePickerView;
- (NSString *)tablePickerView:(TablePickerView *)tablePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
/*!
@brief 自定义每个选项视图,如果现实该代理方法,tablePickerView:titleForRow: forComponent:方法将无效
*/
- (UITableViewCell *)tablePickerView:(TablePickerView *)tablePickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component;
@required
- (NSInteger)tablePickerView:(TablePickerView *)tablePickerView numberOfRowsInComponent:(NSInteger)component;
3、实现视图代理TablePickerViewDelegate
@optional
- (CGFloat) tablePickerView:(TablePickerView *)tablePickerView widthForComponent:(NSInteger)component;
- (CGFloat) tablePickerView:(TablePickerView *)tablePickerView rowHeightForComponent:(NSInteger)component;
- (void) tablePickerView:(TablePickerView *)tablePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
通过以上三步就可以实现table view 的基础多级联动了,主要视图在TablePickerView目录下,具体怎么使用可看源码:git地址
4、需要自定义cell的话,需要调用以下方法注册和获取复用cell
/*!
@biref 获取复用cell
@param identifier 复用唯一标识
@param component 列
@return 返回tableViewCell
*/
- (UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier forComponet:(NSInteger)component;
/*!
@brief 使用xib创建cell
@param identifier 复用唯一标识
@param component 列
*/
- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier forComponet:(NSInteger)component;
/*!
@brief 使用纯代码创建cell
@param identifier 复用唯一标识
@param component 列
*/
- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier forComponet:(NSInteger)component;