iOS精选

UITableViewController中静态Cell和动态C

2016-09-19  本文已影响1466人  sunshinesuns

在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];
}
上一篇 下一篇

猜你喜欢

热点阅读