1.tableView的cell選中后不改變顏色
//選中后不變色
cell.selectionStyle = UITableViewCellSelectionStyleNone;
2.tableView的隱藏線條
self.TableView.separatorStyle = UITableViewCellSeparatorStyleNone;
3.判斷上下拉位移,決定是否隱藏/顯示控件
#pragma mark -- 監(jiān)控滑動(dòng)手勢(shì),判斷是否隱藏頭部
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
// self.oldOffset 是一個(gè)float值
// self.oldOffset = 0;
//如果當(dāng)前位移大于緩存位移,說明向上滑動(dòng)
if (scrollView.contentOffset.y > self.oldOffset) {
//添加你要的方法
}
else if(scrollView.contentOffset.y < self.oldOffset){
//添加你要的方法
}
//將當(dāng)前位移變成緩存位移,這一步不能省略
self.oldOffset = scrollView.contentOffset.y;
}
4.tableCell文件初始化方法
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
return self;
}
5.隱藏tableView滾動(dòng)條
//隱藏垂直滾動(dòng)條
self.marTableView.showsVerticalScrollIndicator = NO;
//隱藏水平滾動(dòng)條
self.marTableView.showsVerticalScrollIndicator = NO;
6.取消tableView彈性效果
self.marTableView.bounces = NO;
7.Cell右邊箭頭
//顯示最右邊的箭頭
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
8.tableviewCell默認(rèn)選中第一條
NSIndexPath *ip=[NSIndexPath indexPathForRow:0 inSection:0];
[myTableView selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionBottom];
9.禁止tableview滾動(dòng)
//禁止tableview滾動(dòng)
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會(huì)隨著滑動(dòng)黏在上方叉寂,直到新的sectionheaderview出現(xiàn)并替換掉蛛芥,這是個(gè)好的特性,但有時(shí)候需求就是辣么的你懂,為了滿足需求,只能這么寫了.
// 去掉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刷新
//一個(gè)section刷新
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
//一個(gè)cell刷新
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];