UITableView去掉最后切割线的一种方法
UITableView以style:UITableViewStylePlain方式创建时。仅仅要有cell,就会有一条黑线 哪怕至于一个cell也会有,如图

在网上找了集中方法,都不好使,比方http://blog.csdn.net/l_ch_g/article/details/9290727,中的两种方法,都尝试不好使
第一种方法
{
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];
}
在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去掉最后切割线的一种方法的更多相关文章
- CSS 去掉inline-block间隙的几种方法
最近做移动端页面时,经常会用到inline-block元素来布局,但无可避免都会遇到一个问题,就是inline-block元素之间的间隙.这些间隙会导致一些布局上的问题,需要把间隙去掉.对于inlin ...
- js 去掉字符串前后空格5种方法
第一种:循环检查替换 //供使用者调用 function trim(s){ return trimRight(trimLeft(s)); } //去掉左边的空白 function trimLeft(s ...
- js去掉字符串前后空格的五种方法
转载 :http://www.2cto.com/kf/201204/125943.html 第一种:循环检查替换[javascript]//供使用者调用 function trim(s){ ret ...
- CSS 去掉inline-block元素间隙的几种方法
最近做移动端页面时,经常会用到inline-block元素来布局,但无可避免都会遇到一个问题,就是inline-block元素之间的间隙.这些间隙会导致一些布局上的问题,需要把间隙去掉.对于inlin ...
- win7桌面图标小盾牌怎么去掉(2种方法)
很多用户都会在桌面上放置一些常用的程序图标,由于win7系统提高了系统安全性,新增用户帐户控制,所以会在图标上显示小盾牌,表示需要管理员权限打开.不少win7 32位旗舰版用户觉得这个小盾牌很碍眼,那 ...
- Android开发之去掉标题栏的三种方法,推荐第三种
Android:去掉标题栏的三种方法和全屏的三种方法 第一种:一般入门的时候常常使用的一种方法 onCreate函数中增加下面代码: requestWindowFeature(Window.FEATU ...
- 5种方法去掉HTML中Inline-Block元素之间的空白
5种方法去掉HTML中Inline-Block元素之间的空白 记得年轻时我在IE6上开发,绝望的希望IE6能支持display: inline-block功能.当需要在”inline”元素上控制mar ...
- 3种方法教你PS快速去掉水印
方法一:使用选框工具 勾选水印部分: 按住Shift+f5选择内容识别: 然后 ctrl+d 取消选择,水印就去掉了 PS:其实这个方法有个快捷办法,直接使用选框工具选中之后,按Delete就可以弹出 ...
- js去掉字符串前后空格的五种方法(转)
出处:http://www.2cto.com/kf/201204/125943.html 第一种:循环检查替换[javascript]//供使用者调用 function trim(s){ retu ...
随机推荐
- 解决IIS服务器部署 字体图标找不到的原因
引言 我们往往在IIS上部署Web项目,或者发布Web项目的时候,经常会遇到浏览器找不到字体文件(woff/woff2)产生的错误.这样会导致浏览器无法加载字体图标,在影响加载时间的同时,更无法显示对 ...
- 深入了解JWT以及JWT的执行机制
1.JWT以什么样的形式存在? eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9 ...
- BZOJ 1355[Baltic2009]Radio Transmission(KMP)
题意 给你一个字符串,它是由某个字符串不断自我连接形成的. 但是这个字符串是不确定的,现在只想知道它的最短长度是多少. (n<=1000000) 题解 这种求最小循环节的题一般是KMP. 因为有 ...
- poj-1151-Atlantis-线段树求面积并
非常裸的线段树求面积并. 坐标须要离散化一下. #include<stdio.h> #include<iostream> #include<stdlib.h> #i ...
- When you are old (当你老了)
- William Butler Yeats --威廉·巴特勒·叶芝 When you are old and grey and full of sleep: 当你老了,头发花白,睡意沉沉. And ...
- 更改linux文件的拥有者及用户组(chown和chgrp)
.使用chown命令更改文件拥有者 在 shell 中,能够使用chown命令来改变文件全部者.chown命令是change owner(改变拥有者)的缩写.须要要注意的是,用户必须是已经存在系统中的 ...
- GraphicsMagick java.io.FileNotFoundException: gm 错误解决办法
GraphicsMagick java.io.FileNotFoundException: gm 解决办法, 方法一: ProcessStarter.setGlobalSearchPath(" ...
- node05---模块
Node.js开发服务器,数据.路由.本地关心的效果,交互: Node.js实际上是极客开发出的一个小玩具,不是银弹.有着别人不具备的怪异特点: 首先,Node不为每个用户开辟一个线程,所以非常单线程 ...
- php中的页面跳转和重定向
php中的页面跳转和重定向 ThinkPHP中跳转和重定向的区别 跳转: 浏览器认为: 当前URL请求成功, 重新请求新的URL. 浏览器会 记录当前的URL 和 新的URL 在请求历史记录中. 回退 ...
- Failed to start metasploit.service: Unit metasploit.service not found的解释
不多说,直接上干货! root@kali:~# service metasploit start Failed to start metasploit.service: Unit metasploit ...