UITableView隐藏多余的分割线
plain类型的tableview当显示的数据很少时,下面的cell即使不显示数据也会有分割线,可以通过下面这个函数去掉杜宇的分割线。
- (void)setExtraCellLineHidden: (UITableView *)tableView
{
UIView *view = [UIViewnew];
view.backgroundColor = [UIColorclearColor];
[tableViewsetTableFooterView:view];
[view release];
}
当tableview的dataSource为空时,也就是没有数据可显示时,该方法无效,只能在numberOfRowsInsection函数,通过判断dataSouce的数据个数,如果为零可以将tableview的
separatorStyle设置为UITableViewCellSeparatorStyleNone去掉分割线,然后在大于零时将其设置为
UITableViewCellSeparatorStyleSingleLine
{
UIView *view = [UIView new];
view.backgroundColor = [UIColor clearColor];
[tableView setTableFooterView:view];
[view release];
}
- (void)viewDidLoad
{
[super viewDidLoad];
//设置tableView不能滚动
[self.tableView setScrollEnabled:NO];
//在此处调用一下就可以啦 :此处假设tableView的name叫:tableView
[self setExtraCellLineHidden:self.tableView];
}
一个关于tableview的细节问题
当tableview style设置为ground时,每个section的header会跟随tableview一起上下滑动;当style设置为plain时,每个section的header会悬浮在屏幕最上面,直到下一个section的header划过来,把当前的替换掉。现在的问题是,可以在style为plain时,让header也跟随tableview一起上下滚动吗,而不停在屏幕最上的部分。。。。大家有遇到这个问题的多多指点交流下也就是如下两图的区别
//去掉UItableview headerview黏性
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.myTableView)
{
CGFloat sectionHeaderHeight = YOUR_HEIGHT;
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);
}
}
}
最好的解决办法是把这个view赋给