ios tableview间隔线效果

来源:互联网 发布:北京php工程师培训 编辑:程序博客网 时间:2024/05/17 22:11

在ios中,遇到一个关于tableview间隔线展示效果的问题,搜索了很多资料,终于找到解决方式。这个功能并不大,算是个小技巧

首先在你的.m文件中创建一个方法

- (void)setExtraCellLineHidden: (UITableView *)tableView

{

    UIView *view = [UIView new];

    view.backgroundColor = [UIColor clearColor];

    [tableView setTableFooterView:view];

    [view release];

}

然后在你创建tableview之后调用这个方法

[selfsetExtraCellLineHidden:mtableView];

mtableView代表的是你所创建的tableview

这里有一点需要注意,

numberOfRowsInSection 在这个方法中,要设定

下面count 是你当前tableview的行数

if(count >0)

    {

        mtableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;

    }

    else {

        mtableView.separatorStyle=UITableViewCellSeparatorStyleNone;

    }

也就是说,当该tableview无内容的时候,要设置间隔线效果无。当然创建tableview的时候,也要设置这个效果为无


原创粉丝点击