iOS 清除UITableView底部多余的分割线

第一种方法

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];

}

当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;


原文地址:

http://blog.csdn.net/l_ch_g/article/details/9290727

其博客地址:

http://blog.csdn.net/l_ch_g?viewmode=contents

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值