從事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;