UITableView基础
来源:互联网 发布:siman淘宝 编辑:程序博客网 时间:2024/05/16 18:19
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的代理方法
0 0
- UITableView基础
- UITableView基础
- UITableView基础
- UItableView基础加深
- IOS UITableView 基础应用
- UITableView(一)---- 基础
- UITableView基础(一)
- UITableView基础语法
- UI基础—UITableView
- iOS基础--UITableView,UITableViewController
- UITableView的基础部分
- UI基础-UITableView 编辑
- UI基础-UITableView 高级
- iOS开发基础 - UITableView
- UITableView 基础篇
- Swift UITableView基础
- UITableView使用基础篇
- UITableView基础 UITableView编辑,UITableViewCell自定义
- bzoj2811 apio2012 守卫 guard 贪心
- dwr3实现消息精确推送详细步骤
- 二分查找-lintcode
- Swift之自定义突出按钮Tabbar
- !function(){}() ” 是什么意思
- UITableView基础
- Windows下安装MySQL5.7
- iOS开发之UIImagePickerController详解
- [spring入门学习笔记][spring的IoC原理]
- Android 深入理解Android中的自定义属性
- 白书游--第一章
- PHP实现凯撒加密算法
- 理解TimesTen错误日志信息"waiting for latch"
- [Spring入门学习笔记][Spring的AOP原理]