1tableview的小设置
在开发中你会发现tableview是个用的最多的控件了,它的用法很简单,但是有些不常用的小的设置,在需要时很难找到,下面就是我个人总结
1.1UITableView的section header view不悬停的方法
在开发中,可能会用到分组的情况,在滑动时headerview会有悬停的情况,下面这个方法可以让它不悬停
- (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);
}
}
1.2如果tableview是竖直滑动的,会在tableview的左边有一条灰色的线,有时需要隐藏,下面这行代码就可以隐藏
//取消滑动时右边的竖线
self.NewTableView.showsVerticalScrollIndicator = NO;
暂时就这些,以后遇到会及时更新的
单独刷新section
//刷新第0组数据
NSIndexSet*indexSet=[[NSIndexSetalloc]initWithIndex:0];
[self.tableView reloadSections:indexSetwithRowAnimation:UITableViewRowAnimationNone];
单独刷新一个cell
[self.tableView reloadRowsAtIndexPaths:<#(nonnull NSArray *)#> withRowAnimation:<#(UITableViewRowAnimation)#>]