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

最近用的uitableviewcontroller比较多,因此也遇到了很多的小问题,在此记录一下,省的下次再犯。
1.首先说在创建部分,我们创建一个继承uitableviewcontroller的控制器HSMoreViewController
tableview的样式有两种分别为:UITableViewStylePlain和UITableViewStyleGrouped

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

首先我们看一下普通样式和分组样式的展示,如图
UITableViewStylePlain
UITableViewStyleGrouped
如果我们需要一个普通样式的,但是又不需要下方多余的分割线怎么办?

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

如此便可以了,试一下运行效果
这里写图片描述
2.tableview 分组样式还有一些细节需要我们注意

//返回头部显示的文字
-(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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值