您的位置:首页 > 产品设计 > UI/UE

UITableviewController的创建以及关于多余分割线问题

2015-08-25 10:29 531 查看
最近用的uitableviewcontroller比较多,因此也遇到了很多的小问题,在此记录一下,省的下次再犯。

1.首先说在创建部分,我们创建一个继承uitableviewcontroller的控制器HSMoreViewController

tableview的样式有两种分别为:UITableViewStylePlain和UITableViewStyleGrouped

[code]HSMoreViewController *More=[[HSMoreViewController alloc]initWithStyle:UITableViewStyleGrouped];
//如果我们直接[HSMoreViewController *More=[[HSMoreViewController alloc]init]则创建出来的就是默认样式UITableViewStylePlain,在默认样式下,多余的分割线是不会隐藏的


首先我们看一下普通样式和分组样式的展示,如图







如果我们需要一个普通样式的,但是又不需要下方多余的分割线怎么办?

[code]- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView setTableFooterView:[[UIView alloc]initWithFrame:CGRectZero]];
}


如此便可以了,试一下运行效果




2.tableview 分组样式还有一些细节需要我们注意

[code]//返回头部显示的文字
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return @"第一组头部";
    }
    return @"第二组头部";
}
//返回每一组底部显示的文字
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    if (section==0) {
        return @"第一组底部";
    }
    return @"第二组底部";
}
//返回头部的高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}
//返回底部的高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: