美文网首页
UItableViwe的基本使用

UItableViwe的基本使用

作者: 小热带雨林 | 来源:发表于2020-04-05 12:10 被阅读0次

UItableView在实际使用时会根据需求的不同进行不同的设置

自定义cell

1.注册,需要几种cell注册几种cell,根据组号的不同进行替换即可
2.行高(最好是设置预估行高,让cell的内容将cell撑开)

//通过代理方式设置行高,同时可以根据组号设置不同组号的行高
- (CGFloat)tableView:(UITableView*)tableViewheightForRowAtIndexPath:(NSIndexPath*)indexPath{
    if(indexPath.row==0)
        return200;
    return200;
}
//设置预估行高
    self.tableViwe.estimatedRowHeight = 200;
    self.tableViwe.rowHeight = UITableViewAutomaticDimension;
自定义表头表尾

1.自定义表头
表头的的大小是根据自定义的view进行设置的,不需要tableView进行设置

- (void)setUpHeaderView{
    GGTableViewHeaderView *headerView = [[GGTableViewHeaderView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 350)];
    self.tableView.tableHeaderView = headerView;
}

2.自定义表尾
同上

- (void)setUpFooterView{
    GGTableViewFooterView *footerView = [[GGTableViewFooterView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 70)];
    footerView.delegate = self;
    self.tableView.tableFooterView = footerView;
}
自定义组头组尾

1.自定义组头
根据需求的可以根据组号设置不同高度和视图

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if(section == 0)
        return 200;
    return GGTableViewHeaderH;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if(section == 0){
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), GGTableViewHeaderH)];
          view.backgroundColor = [UIColor blueColor];
          return view;
    }
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), GGTableViewHeaderH)];
    view.backgroundColor = [UIColor blueColor];
    
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), GGTableViewHeaderH)];
    title.text = self.dataList[section].title;
    title.textAlignment = NSTextAlignmentCenter;
    [view addSubview:title];
    return view;
}

2.设置组尾
同上

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if(section == 0)
        return 200;
    return GGTableViewFooterH;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if(section == 0){
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), GGTableViewFooterH)];
        view.backgroundColor = [UIColor redColor];
        return view;
    }
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), GGTableViewFooterH)];
    view.backgroundColor = [UIColor redColor];
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), GGTableViewFooterH)];
    title.text = @"footer";
    title.font = [UIFont systemFontOfSize:11];
    [view addSubview:title];
    return view;
}
拓展

1.tableView的索引

- (NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView{
    return [self.dataList valueForKey:@"title"];
}

2.组头组尾设置文字

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return self.dataList[section].title;
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
    return @"footer";
}

相关文章

  • UItableViwe的基本使用

    UItableView在实际使用时会根据需求的不同进行不同的设置 自定义cell 1.注册,需要几种cell注册几...

  • iOS总结:

    1:(在5/5s下绘制控件)UITableViwe中,自定义cell如果用系统的箭头,则在做适配时 遇到大屏幕显示...

  • 基本的使用

    存cookie 取cookie 存session 取session

  • Flutter--Text/Container/Image

    Text基本使用 Container基本使用 Image基本使用

  • 基本使用

    1、 打开需要上传的文件夹执行: git init 格式化窗口 2、执行 git add . 上传文件 3、执行 ...

  • 基本使用

    href="javascript:;" 其中javascript: 是一个伪协议。它可以让我们通过一个链接来调用...

  • 基本使用

    数据库: 什么是数据库?简单来说就是存数据的。 都有什么是数据库? oracle(强大,跟金融政府打交道的,安全,...

  • 基本使用

    本文参考:https://morvanzhou.github.io/tutorials/machine-learn...

  • SQL语句基本使用

    SQL语句基本使用——增删改查 SQL语句基本使用——WHERE子句 SQL语句基本使用——AND和OR的使用 S...

  • 6-xpath和css select基本使用

    Xpath基本使用 css select基本使用

网友评论

      本文标题:UItableViwe的基本使用

      本文链接:https://www.haomeiwen.com/subject/qbfuphtx.html