从事ios工做有段时间了,其中UItableView频繁被使用中,这个过程当中不断重复的建立加入代理,好麻烦,并且也让viewcontroller代码显的臃肿,所以作了下面的封装ios
tableview建立的工做作一次git
获取数据过程当中就把最后须要多少个section,多少个cell的工做作完,后续直接用github
tableviewcell的高度计算,数据填充都让cell本身去作json
简单的一个使用样例
代理
//数据源填充code
-(void)createDataSource{ XCTableViewDataSection *section = [[XCTableViewDataSection alloc] init]; [section.rowModelsArr addObject:@"1"]; [section.rowModelsArr addObject:@"2"]; [section.rowModelsArr addObject:@"3"]; [section.rowModelsArr addObject:@"4"]; [self.dataSource.sections addObject:section]; }
//cellforrow相似功能事件
-(Class)xctableView:(UITableView *)tableView cellClassAtModel:(id)model{ return [TableViewCell1 class]; }
//tableviewcell的点击事件get
-(void)xctableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath model:(id)model{ [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; }
设置高度it
-(CGFloat)xctableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 100; }
赋值io
-(void)xcSetModel:(id)model forIndexPath:(NSIndexPath *)indexPath{ _lbName.text = model; }
/************设置tableviewcell *******/ //经过model判断加入不一样的tableViewCell -(Class)xctableView:(UITableView *)tableView cellClassAtModel:(id)model; //经过indexpath判断加入不一样的tableViewCell -(Class)xctableView:(UITableView *)tableView cellClassAtIndexPath:(NSIndexPath *)indexPath; /********tableviewcell中操做反馈做用的代理 *******/ -(void)xctableviewCell:(XCTableViewCell *)cell; -(void)xctableviewCell:(XCTableViewCell *)cell model:(id)model; -(void)xctableviewCell:(XCTableViewCell *)cell button:(UIButton *)button model:(id)model;
/*****提供经过indexpath和数据两种方法判断设置高度 *******/ -(CGFloat)xctableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; -(CGFloat)xctableView:(UITableView *)tableView heightForRowAtModel:(id)Model;