UITableViewController的簡單使用

協(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;

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容