UITableView以style:UITableViewStylePlain方式创建时。仅仅要有cell,就会有一条黑线 哪怕至于一个cell也会有,如图

在网上找了集中方法,都不好使,比方http://blog.csdn.net/l_ch_g/article/details/9290727,中的两种方法,都尝试不好使

第一种方法

 
1、加方法
-(void)setExtraCellLineHidden: (UITableView *)tableView
{
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
    [view release];
}
 
2、在

- (void)viewDidLoad

{

[super viewDidLoad];

//设置tableView不能滚动

[self.tableView setScrollEnabled:NO];

//在此处调用一下就能够啦 :此处如果tableView的name叫:tableView

[self setExtraCellLineHidden:self.tableView];

}

在iOS4.3和iOS5.0中通过:值得注意的是在iOS4.3中能够直接设置footer为nil。可是在5.0不行。由于UITableView会默认生成一个Footer。

(详见iOS Release Notes中的说明:Returning nil from the tableView:viewForHeaderInSection: method (or its footer equivalent) is no longer sufficient to hide a header. You must override tableView:heightForHeaderInSection: and return 0.0 to hide a header.)

plain类型的tableview当显示的数据非常少时,以下的cell即使不显示数据也会有切割线。能够通过以下这个函数去掉多余的切割线。

- (void)setExtraCellLineHidden: (UITableView *)tableView

{

UIView *view =[ [UIView alloc]init];

view.backgroundColor = [UIColor clearColor];

[tableView setTableFooterView:view];

[view release];

}

当tableview的dataSource为空时,也就是没有数据可显示时。该方法无效,仅仅能在numberOfRowsInsection函数。通过推断dataSouce的数据个数。如果为零能够将tableview的separatorStyle设置为UITableViewCellSeparatorStyleNone去掉切割线,然后在大于零时将其设置为

UITableViewCellSeparatorStyleSingleLine

 

另外一种方法

if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; // Drawing our own separatorLine here because I need to turn it off for the
// last row. I can only do that on the tableView and on on specific cells.
// The y position below has to be 1 less than the cell height to keep it from
// disappearing when the tableView is scrolled.
UIImageView *separatorLine = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, cell.frame.size.height - 1.0f, cell.frame.size.width, 1.0f)];
separatorLine.image = [[UIImage imageNamed:@"grayDot"] stretchableImageWithLeftCapWidth:1 topCapHeight:0];
separatorLine.tag = 4; [cell.contentView addSubview:separatorLine]; [separatorLine release];
} // Setup default cell setttings.
...
UIImageView *separatorLine = (UIImageView *)[cell viewWithTag:4];
separatorLine.hidden = NO;
...
// In the cell I want to hide the line, I just hide it.
seperatorLine.hidden = YES;
...

In viewDidLoad:

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 

最后,创建UITableView时,使用style:UITableViewStyleGrouped,方法解决这个问题。

​代码例如以下

1 self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
2  
3 _tableView.separatorColor = [UIColor clearColor];
4 _tableView.backgroundView=[[UIView alloc] init];    //改变表的背景视图
5 _tableView.backgroundColor = [UIColor whiteColor]; //加入颜色

使用UITableViewStyleGrouped类型创建的UITableView。背景颜色须要使用上面两个方法设置的才干生效,普通的backgroundcolor方法无效。
同一时候由于UITableViewStyleGrouped模式默认会有Section高度,所以。要继承下heightForHeaderInSection方法,记住在UITableViewStyleGrouped,直接改动sectionHeaderHeight的方式是不行的。

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
// This will create a "invisible" footer
return 0.01f;
}

UITableView去掉最后切割线的一种方法的更多相关文章

  1. CSS 去掉inline-block间隙的几种方法

    最近做移动端页面时,经常会用到inline-block元素来布局,但无可避免都会遇到一个问题,就是inline-block元素之间的间隙.这些间隙会导致一些布局上的问题,需要把间隙去掉.对于inlin ...

  2. js 去掉字符串前后空格5种方法

    第一种:循环检查替换 //供使用者调用 function trim(s){ return trimRight(trimLeft(s)); } //去掉左边的空白 function trimLeft(s ...

  3. js去掉字符串前后空格的五种方法

    转载 :http://www.2cto.com/kf/201204/125943.html 第一种:循环检查替换[javascript]//供使用者调用  function trim(s){  ret ...

  4. CSS 去掉inline-block元素间隙的几种方法

    最近做移动端页面时,经常会用到inline-block元素来布局,但无可避免都会遇到一个问题,就是inline-block元素之间的间隙.这些间隙会导致一些布局上的问题,需要把间隙去掉.对于inlin ...

  5. win7桌面图标小盾牌怎么去掉(2种方法)

    很多用户都会在桌面上放置一些常用的程序图标,由于win7系统提高了系统安全性,新增用户帐户控制,所以会在图标上显示小盾牌,表示需要管理员权限打开.不少win7 32位旗舰版用户觉得这个小盾牌很碍眼,那 ...

  6. Android开发之去掉标题栏的三种方法,推荐第三种

    Android:去掉标题栏的三种方法和全屏的三种方法 第一种:一般入门的时候常常使用的一种方法 onCreate函数中增加下面代码: requestWindowFeature(Window.FEATU ...

  7. 5种方法去掉HTML中Inline-Block元素之间的空白

    5种方法去掉HTML中Inline-Block元素之间的空白 记得年轻时我在IE6上开发,绝望的希望IE6能支持display: inline-block功能.当需要在”inline”元素上控制mar ...

  8. 3种方法教你PS快速去掉水印

    方法一:使用选框工具 勾选水印部分: 按住Shift+f5选择内容识别: 然后 ctrl+d 取消选择,水印就去掉了 PS:其实这个方法有个快捷办法,直接使用选框工具选中之后,按Delete就可以弹出 ...

  9. js去掉字符串前后空格的五种方法(转)

    出处:http://www.2cto.com/kf/201204/125943.html 第一种:循环检查替换[javascript]//供使用者调用  function trim(s){  retu ...

随机推荐

  1. pycharm修改提示

  2. LightOJ-1336 Sigma Function 唯一分解定理 巧妙使用sqrt()等算数目

    题目链接:https://cn.vjudge.net/problem/LightOJ-1336 题意 给出一个区间[1, n],求区间内所有数中因数之和为偶数的数目 思路 第二次写这个题 首先想到唯一 ...

  3. SFTP使用key文件登录

    命令: sftp -oPort= -oIdentityFile=/root/.ssh/user.priv user@39.39.100.100 命令选项: -o ssh_option Can be u ...

  4. vue之computed和watch

    计算属性 computed 侦听器or观察者 watch 一直以来对computed和watch一知半解,用的时候就迷迷糊糊的,今天仔细看了看文档,突然茅塞顿开,原来就是这么简单啊: computed ...

  5. hook中ref使用

    hook使用ref 父组件: 引入                  useRef 声明ref的名字     const dateRef = useRef() 复值给组件         ref={d ...

  6. 【BZOJ 1193】 [HNOI2006]马步距离

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 原问题可以等价为两个点. 然后其中一个点要移动到另外一个点. 那么我们可以把左下角那个点(对称总是可以得到一个点在左下角)放在原点的 ...

  7. Qt 学习之路问题

    Qt5 cannot include the file QMainWindow add "greaterThan(QT_MAJOR_VERSION, 4): QT += widgets&qu ...

  8. 【LeetCode OJ 34】Search for a Range

    题目链接:https://leetcode.com/problems/search-for-a-range/ 题目:Given a sorted array of integers, find the ...

  9. SQLSever: 怎样在select中的每一行产生不同的随机数?

    select 的随机函数有点假, 或许是由于它是基于时间来的吧, 同一select中由于时间无法错开导致产生的随机数都是一样的. 怎样做到让不同的行拥有不同的随机数呢? 以下以产生某个月的随机日期来演 ...

  10. mysql---左连接、右连接、内连接之间的差别与联系

    现有两张表 第一张表为男生表,记录了男生的姓名和配偶的编号 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbXlfbWFv/font/5a6L5L2T/fo ...