協(xié)議
<UITableViewDelegate,UITableViewDataSource>
注冊Cell
static NSString *const XXCellId = @"XXCellId";
[self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([XXCell class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:XXCellId];
初始化。賦值
XXCell *cell = [tableView dequeueReusableCellWithIdentifier:XXCellId];
cell.cellData = self.xxModel;
cell.cellData.indexPath = indexPath;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
獲取數(shù)據(jù)源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [[self.XXModel.xxx yyy] count];
}
返回幾個區(qū)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
區(qū)頭
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headerView = [[UIView alloc] init]]
return headerView;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *footerView = [[UIView alloc] init]]
return footerView;
}
返回區(qū)頭高度&返回區(qū)尾高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 20;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 20;
}
rowHeight估算高度
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
}
自適應高度方法之一
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewAutomaticDimension;
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
}
表頭
self.tableView.tableHeaderView = self.topView;
cell的點擊事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
消除間隔線
self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;