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. HDU-5685 Problem A 求乘法逆元

    题目链接:https://cn.vjudge.net/problem/HDU-5685 题意 给一个字符串S和一个哈希算法 $ H(s)=\prod_{i=1}^{i\leq len(s)}(S_{i ...

  2. java 模拟ajax上传图片

    1.maven 引入依赖 <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime --> &l ...

  3. vue-router query和params传参(接收参数)$router $route的区别

    今天做项目时踩到了vue-router传参的坑(query和params),所以决定总结一下二者的区别. 直接总结干货!!! 1.query方式传参和接收参数 传参: this.$router.pus ...

  4. Extjs4.2 tooltip 提示宽度问题解决

    在Extjs4.2 的tooltip 提示,宽度被限制在了40px,感觉非常别扭,是个BUG,解决的方法,在ext-all-debug.js或ext-all.js中,找到例如以下的代码: Ext.de ...

  5. Android bluetooth介绍(一):基本概念及硬件接口

    关键词:蓝牙硬件接口 UART  PCM  blueZ 版本号:基于android4.2之前版本号 bluez内核:linux/linux3.08系统:android/android4.1.3.4作者 ...

  6. 4、python序列对比

    1.列表:[ ],杂(什么都可以放进去),有序,可变 2.元组:(),有序,不可变 3.字典:{ },键值对,无序,可变 4.集合:{ },不可重复,无序,可变

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

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

  8. TCO14 1B L3: EagleInZoo, dp,tree

    题目:http://community.topcoder.com/stat?c=problem_statement&pm=13117&rd=15950 看到树,又是与节点有关,通常是d ...

  9. nyoj-673-悟空的难题(数组标记)

    悟空的难题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 自从悟空当上了齐天大圣.花果山上的猴子猴孙们便也能够尝到天上的各种仙果神酒,所以猴子猴孙们的体质也得到了非 ...

  10. springBoot 打war包 程序包com.sun.istack.internal不存在的问题

    使用的是 idea - Lifecycle-package 的方式打包(maven) 确认  <packaging>war</packaging> 修改启动类: (原启动类) ...