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

来源:互联网 发布:c语言char函数 编辑:程序博客网 时间:2024/06/07 01:13

最近用的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