1.tableView的样式
1.分段显示UITableViewStylePlain 分段显示,当滑动tableView的时候每组的头部会顶在最上方知道该组所有内容消失换成下一组
2.分组显示 UITableViewStyleGrouped
2.tableView显示每组头部和尾部的文字通过以下两个方法设置,同样tableView的样式不同显示就不同,如上图所示
1.设置每组的标题和段脚
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
2.设置每组标题和段脚的高度
tableView.sectionFooterHeight = 100;
tableView.sectionHeaderHeight = 10;
3.tableViewCell的分割线
1.分割线属性
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
2.分割线的颜色
tableView.separatorColor = [UIColor redColor];
4.在设置tableView的颜色时需要注意要消除cell 的颜色,不然tableView的颜色会被覆盖
5.cell默认情况下是可以选中的通过设置tableView.allowsSelection = NO可以设置不选中
6.刷新tableView
1.刷新所有行的数据
[self.tableView reloadData];特别需要注意的是刷新tableView,tableView会重新创建tableView的内容,不从缓存池中取
2.刷新指定行的数据
//刷行指定行的数据
[self.tableView reloadRowsAtIndexPaths:<#(NSArray *)#> withRowAnimation:<#(UITableViewRowAnimation)#>];
7.使tableView滚动到表格的指定一行
NSIndexPath *path = [NSIndexPath indexPathForRow:5 inSection:1];
[self.tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionBottom animated:YES];
//atScrollPosition 显示滚动这个位置在屏幕上是什么位置
/*
UITableViewScrollPositionNone,
UITableViewScrollPositionTop,//屏幕的顶部
UITableViewScrollPositionMiddle,//中间
UITableViewScrollPositionBottom//底部
*/
8.获取段数及行数
NSLog(@"%ld",self.tableView.numberOfSections);
NSLog(@"%ld",[self.tableView numberOfRowsInSection:1]);
9.获取到被选中的indexPath
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
10.条目多选
tableView.allowsMultipleSelection = YES;
11.设置所有表格行高
tableView.rowHeight = 100;
12.在tableView的头部或者尾部添加view,footerView宽度是不用设置的
self.tableView.tableFooterView =xxxView;
self.tableView.tableHeaderView =xxxView;
13.增加tableview滚动区域
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, xx, 0);