nicklockwood / layout

A declarative UI framework for iOS
MIT License
2.23k stars 97 forks source link

UITableViewCells underneath headerview #120

Closed joelbanzatto closed 6 years ago

joelbanzatto commented 6 years ago

Hello,

I am trying to put a Header View into TableView this way:

<UIView width="100%" height="100%" backgroundColor="#ffffff">
    <UITableView
      left="0"
      top="0"
      height="100%"
      width="100%"
      style="grouped"
      outlet="tableView"
      estimatedSectionHeaderHeight="80"
    >
      <UITableViewHeaderFooterView
        backgroundView.backgroundColor="#4267B2"
        height="auto + 10"
        reuseIdentifier="profileHeader"
      >
        <AvatarImageView
          height="64" width="64"
          top="20" left="20"
          id="avatar"
        />
        <UILabel
          font="16 bold"
          textColor="white"
          text="Person Name LastName"
          top="previous.top"
          left="#avatar.right + 10"
        />
        <UILabel
          font="14"
          textColor="white"
          text="Location Name"
          top="previous.bottom + 8"
          left="previous.left"
        />
      </UITableViewHeaderFooterView>
      <UITableViewCell
        height="60"
        reuseIdentifier="countryCell"
        accessoryType="disclosureIndicator"
      >
        <RemoteImageView
          id="flag"
          width="32" height="32"
          left="15"
          center.y="parent.center.y"
          url="http://www.countryflags.io/BR/flat/48.png"
        />
        <UILabel
          font="16"
          text="Brazil"
          left="#flag.right + 10"
          center.y="#flag.center.y"
          />
      </UITableViewCell>
    </UITableView>
</UIView>

But the cells come underneath the header view (screenshot) what I am doing wrong?

screen shot 2018-05-04 at 13 30 26

Thanks!

nicklockwood commented 6 years ago

Unfortunately it seems like UITableView doesn’t handle automatic height calculation for table sections headers correctly and I haven’t managed to work out why yet.

It looks like the height of your header is fixed by the avatar image size anyway, so if you set the tableView sectionHeaderHeight to 80 instead of the estimatedSectionHeader height I think that will work.

joelbanzatto commented 6 years ago

@nicklockwood It works greatly fine if you use UIView instead the UITableViewHeaderFooterView.

Thanks for your reply!

nicklockwood commented 6 years ago

@joelbanzatto ah right, I thought you were using it as a section header not a header for the whole table. UITableViewHeaderFooterView is only used for section headers.