开发者

How can I adjust the space between sections in a grouped Table View?

I have a tableview that is basically four sections in length, designed for user input. I am not 开发者_StackOverflow社区using headers or footers as of now.

Section 0 has 4 rows. Section 1 has 2 rows. Section 2 has 1 row. Section 3 has 1 row.

I want to have section 2 and 3 a little closer together and sections 0 and 1 a little closer together - basically configuring the space in between cells.

I have searched far and wide and have found nothing specific on how to do this. Suggestions?

Thank you in advance,


Handle

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

More info here:

UITableView Not Respecting heightForHeaderInSection/heightForFooterInSection?


If your tableview is set to Grouped, and not Plain, you can use the default invisible footers as padding. This way you can leave your headers looking good (and not have a giant gap above the first section)

  func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
      if section == 0 || section == 2 {
        return 20
      } else {
        return 40
      }
  }

Just FYI, if you return 0 it will ignore it and go with the default amount. To completely hide the footer, set it to 0.0001 or something

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜