1.tableView的cell选中后不改变颜色
//选中后不变色
cell.selectionStyle = UITableViewCellSelectionStyleNone;
2.tableView的隐藏线条
self.TableView.separatorStyle = UITableViewCellSeparatorStyleNone;
3.判断上下拉位移,决定是否隐藏/显示控件
#pragma mark -- 监控滑动手势,判断是否隐藏头部
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
// self.oldOffset 是一个float值
// self.oldOffset = 0;
//如果当前位移大于缓存位移,说明向上滑动
if (scrollView.contentOffset.y > self.oldOffset) {
//添加你要的方法
}
else if(scrollView.contentOffset.y < self.oldOffset){
//添加你要的方法
}
//将当前位移变成缓存位移,这一步不能省略
self.oldOffset = scrollView.contentOffset.y;
}
4.tableCell文件初始化方法
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
return self;
}
5.隐藏tableView滚动条
//隐藏垂直滚动条
self.marTableView.showsVerticalScrollIndicator = NO;
//隐藏水平滚动条
self.marTableView.showsVerticalScrollIndicator = NO;
6.取消tableView弹性效果
self.marTableView.bounces = NO;
7.Cell右边箭头
//显示最右边的箭头
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
8.tableviewCell默认选中第一条
NSIndexPath *ip=[NSIndexPath indexPathForRow:0 inSection:0];
[myTableView selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionBottom];
9.禁止tableview滚动
//禁止tableview滚动
self.TableView.scrollEnabled = NO;
10.去除tableView 尾部多余部分
//插入尾部,去除多余的cell,变成空白
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
11.UITableViewCell重用解决
Paste_Image.png
12.去掉tableview中section的headerview粘性
ios的tableview中headerview会随着滑动黏在上方,直到新的sectionheaderview出现并替换掉,这是个好的特性,但有时候需求就是辣么的你懂,为了满足需求,只能这么写了.
// 去掉UItableview headerview黏性(sticky)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat sectionHeaderHeight = 40;
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
}
else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
13.指定某行cell或某section刷新
//一个section刷新
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
//一个cell刷新
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];