UITableView 表视图 代码设置相关属性
来源:互联网 发布:网络教育本科第二学位 编辑:程序博客网 时间:2024/05/22 19:57
1.设置分割线的风格和颜色
tableV.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
tableV.separatorColor= [UIColorgreenColor];
2.设置单元格高度 动态设置单元格高度可以在代理方法里设置
tableV.rowHeight=50;
3.设置头视图
tableV.tableHeaderView= imgV;
4.刷新数据 会重新调用dataSource方法
[tableVreloadData];
5.获取并修改某个单元格的数据 但是只能修改显示了的cell的值 否则返回的cell为nil
NSIndexPath*indexPath = [NSIndexPathindexPathForRow:3inSection:0];
UITableViewCell*cell = [tableVcellForRowAtIndexPath:indexPath];
cell.textLabel.text=@"fuck";
6.返回当前显示的所有单元格
NSArray*visibles = [tableVvisibleCells];
7.返回当前显示的所有单元格的indexPath
NSArray*indexPaths = [tableVindexPathsForVisibleRows];
8.将某一个单元格滑动到顶部
[tableVscrollToRowAtIndexPath:indexPathatScrollPosition:UITableViewScrollPositionTopanimated:YES];
9.cell单元格里面封装了三个子视图imageView,textLabel,detailTextLabel 都是只读属性
cell.textLabel.text=_fontNames[indexPath.row];
cell.imageView.image= [UIImageimageNamed:_imageNames[indexPath.row]];
cell.detailTextLabel.text=@"字体";
10.cell设置背景视图
cell.backgroundView= [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"1.jpg"]];
11.cell右边配置类型 可以选打钩之类的
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
12.cell右边配置类型的视图 也可以自定义视图
cell.accessoryView= [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"1.jpg"]];
13.设置字和图片的间隙 水平缩进(这些都对针对于系统提供样式的修改 实际开发中一般都是自定义样式 所以根本用不上)
cell.indentationLevel=3.0;
14.设置缩进宽度
cell.indentationWidth=20;
15.设置字和图片的间隙
cell.separatorInset=UIEdgeInsetsMake(0,0,0,0);
16.这个代理方法如果返回nil 将无法选中单元格
- (nullableNSIndexPath*)tableView:(UITableView*)tableView willSelectRowAtIndexPath:(NSIndexPath*)indexPath {
return indexPath;
return indexPath;
}
17.单元格的重用 (最普通的方式)
UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:kReuseCellID];
if(cell ==nil) {
//相同的内容放在里面
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:kReuseCellID];
}
单元格重用时导致图片文字重叠问题解决方案
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"classifyReuseID"forIndexPath:indexPath];
if (cell) {
// 判断cell.contentView如果有子视图则移除
while ([cell.contentView.subviewslastObject] != nil) {
[[cell.contentView.subviewslastObject] removeFromSuperview];
}
}
18.dataSource方法实现设置标题功能
- (nullableNSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section
19.设置组标题底部的文字
- (nullableNSString*)tableView:(UITableView*)tableView titleForFooterInSection:(NSInteger)section
20.设置头视图高度 在delegate中
- (CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
21.headView 设置颜色 直接设置背景颜色无法成功 要设置headView上的contentView才有效果
headView.contentView.backgroundColor= [UIColorgreenColor];
headView.backgroundColor= [UIColorredColor];
22.头视图上添加子视图要添加到contentView上 头视图也要使用重(chong)用机制 要用UITableViewHeadFootView创建头视图
[tableHeadView.contentViewaddSubview:titleButton];
23.根据contentView上的子视图取出上面的button
UIButton*titleButton = [tableHeadView.contentView.subviewslastObject];
24.这两个分别是设置全局的头视图和组头视图
self.tbV.tableHeaderView
- (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
25.单元格可以设置静态的单元格 有些不需要运行时改变单元格个数的可以这样设置
26.设置导航栏 标签栏透明时 tableView自动向下偏移
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// NSLog(@"%@",self.view);
// NSLog(@"%@",NSStringFromUIEdgeInsets(self.tbV.contentInset));
//导航栏标签栏设置透明时tableView都会分别向下偏移64 向上偏移49
[super viewDidAppear:animated];
// NSLog(@"%@",self.view);
// NSLog(@"%@",NSStringFromUIEdgeInsets(self.tbV.contentInset));
//导航栏标签栏设置透明时tableView都会分别向下偏移64 向上偏移49
}
27.tableView设置分组样式时 上面的空隙是整个tableView的头视图 要在代理方法里设置成0.1才可以做到看不出效果
0 0
- UITableView 表视图 代码设置相关属性
- UITableView 相关属性的设置
- UITableView的相关属性
- IOS学习笔记(十二)之IOS开发之表视图(UITableView)的相关类,属性与表视图实现学习(二)
- IOS学习笔记(十二)之IOS开发之表视图(UITableView)的相关类,属性与表视图实现学习(二)
- UIday0901:UITableView 1 表视图的属性和用法 1
- UIScrollView && UITableView相关属性汇总
- UIScrollView && UITableView相关属性汇总
- UITableView 相关属性和方法
- UITableView表视图控件
- swift UITableView 表视图
- UITableView 表视图
- UITableView 表视图
- UI UITableView表视图
- UITableView 表视图
- UITableView表视图
- UITableView 表视图
- UITableView(表视图)
- String源码解析
- 自治系统中单个路由表的构造
- Windows设计原理分析
- HTML第六章课后作业4
- HDU 5918 KMP变形
- UITableView 表视图 代码设置相关属性
- 一致性哈希算法的实现
- 屏幕适配方案系列一
- Oculus Mobile 端Gear VR 开发
- acm中java的使用
- Java图形界面-JComboBox
- 开发的准备工作
- codeforces round#377 div2 D
- android6.0系统 PowerManager深入分析(非常详细)