UITableView基础
2016-04-13 23:50
405 查看
UITableView
UITableView的常见设置
// 设置tableView的样式(只读,可在storyBoard中修改) plain样式下 section的heder和footer会有悬浮效果(通讯录) group样式 section的头部和底部会默认的有一块间距 // 设置每一行cell的高度 self.tableView.rowHeight = 100; // 设置每一组头部的高度 self.tableView.sectionHeaderHeight = 50; // 设置每一组尾部的高度 self.tableView.sectionFooterHeight = 50; // 设置分割线颜色 self.tableView.separatorColor = [UIColor redColor]; // 设置分割线样式 self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; // 设置表头控件 显示在内容的最前面,一开始就可以看见 self.tableView.tableHeaderView = [[UISwitch alloc] init]; // 设置表尾控件 显示在内容的最后面,一开始看不见 self.tableView.tableFooterView = [UIButton buttonWithType:UIButtonTypeContactAdd]; // 设置右边索引文字的颜色 self.tableView.sectionIndexColor = [UIColor redColor]; // 设置右边索引文字的背景色 self.tableView.sectionIndexBackgroundColor = [UIColor blackColor];
TableView常用属性
tableView.rowHeight 行高 tableView.separatorcolor 分割线颜色 分割线样式 tabbleView.separatorStyle // UITableViewCellSepartorStyleNone 分割线隐藏 tableView.sectionHeaderHeight 每一组的头部高度 tableView.sectionFooterHerght 每一组的尾部高度 可以在cell底部添加一个view 设置高度为小于1作为全屏分割线或者利用透明度
UITableView的索引条是按顺序排列的并不是按对应的索引来排序的
// 返回tableView索引数组 - (nullable NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView
UITableView基础
设置dataSource数据源实现方法
只有一组的时候可以不实现
告诉tableView一共有多少组(默认是0行)
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
必须实现告诉tableView每组有多少行
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
必须实现告诉tableView没行显示什么数据(cell)
(UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
可选实现
// 告诉tableView第section组的头部标题 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section // 告诉tableView第section组的尾部标题 - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
tableView面对模型开发
多组tableView需要的数据 1.组模型 包含行模型,上标题(titleForHeader),下标题(titleForFooter) 2. 行模型 --> 对应cell需要的数据 图片,主标题,副标题等 单组tableView需要的数据 1. 行模型 --> 对应cell需要的数据
常用TableView代理方法
// 选中调用cell时调用 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath // 取消点击调用 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath // 告诉tableView第indexPath行的行高 heightForRow - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath // 修改头部高度 -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section // 修改底部高度 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section // 设置顶部控件 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section // 设置底部控件 - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section // tableView继承自scrollView,tableView的代理同时可以使用scrollView的代理方法
4000
相关文章推荐
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- ios8 UITableView设置 setSeparatorInset UIEdgeInsetsZero不起作用的解决办法(去掉15px空白间距)
- iOS程序开发中设置UITableView的全屏分隔线的方法(不画线)
- 讲解iOS开发中UITableView列表设计的基本要点
- iOS应用开发中UITableView的分割线的一些设置技巧
- 实例讲解iOS应用开发中使用UITableView创建自定义表格
- 全面解析iOS应用中自定义UITableViewCell的方法
- iOS App中UITableView左滑出现删除按钮及其cell的重用
- iOS开发中UITableview控件的基本使用及性能优化方法
- 详解iOS开发中UItableview控件的数据刷新功能的实现
- UITableView 实现汽车品牌(demo)
- 改变iOS应用中UITableView的背景颜色与背景图片的方法
- iOS开发之UITableView详解
- IOS 9 UITableView整理
- UITableView 基本使用方法总结
- UITableView一些易混属性和方法
- UITableView的详细讲解
- (转)UITableViewController重要配置方法和Delegate
- UITableView详细用法,UITableView指南,UITableView详细教程
- ios隐藏uitableview下面多余的tableview的线条