UITableViewController中静态Cell和动态Cell的混合使用

在storyboard中设置对应section的cell的重用id,自定义单元格以及布局好静态单元格,需注册cell以及重写以下代理方法

[self.tableView registerNib:[UINib nibWithNibName:@"CustomCellTableViewCell" bundle:nil] forCellReuseIdentifier:@"Test"];

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   if (section == 1) {
      return 5;
    }
  return [super tableView:tableView numberOfRowsInSection:section];
 }

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath   *)indexPath {
  if (indexPath.section == 1) {
      CustomCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Test" forIn  dexPath:indexPath];
    return cell;
}
  return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 1) {
    return [super tableView:tableView indentationLevelForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
}
  return [super tableView:tableView indentationLevelForRowAtIndexPath:indexPath];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 1) {
    return 88;
}
  return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 前言 最近忙完项目比较闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助。博主非科班出身,一些...
    GitHubPorter阅读 1,476评论 9 5
  • { 24、Sqlite数据库 1、存储大数据量,增删改查,常见管理系统:Oracle、MSSQLServer、DB...
    CYC666阅读 980评论 0 1
  • 版权声明:未经本人允许,禁止转载. 1. TableView初始化 1.UITableView有两种风格:UITa...
    萧雪痕阅读 2,921评论 2 10
  • 自定义单元格 表格无论有多少中自定义单元格样式 每一种自定义单元格都有复用的能力所以每一个单元格都要带有一个静态局...
    DVWang阅读 282评论 0 0
  • 我正读大二,原本性格开朗活泼的我正逐渐走向抑郁症。起因是高三的转班,这是我现在最后悔的一件事,如果没有转班我就不会...
    清风朗月阿云阅读 629评论 0 0