-1

So my goal is to achieve automatic height for my table view. What I mean by by that is whenever I add new item to the table view, the table is still "full screen" while the cell is decreasing its height.

for example this is what I've done :

on iPhone 6s Simulator

on iPhone 5s Simulator

and I've achieve that using code :

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    let itemCount:CGFloat = CGFloat(items.count)
    let statusHeight = UIApplication.shared.statusBarFrame.height
    let navHeight = self.navigationController!.navigationBar.frame.height-statusHeight
    let viewHeight = view.bounds.height
    let cellHeight = (viewHeight-navHeight)/itemCount
    return cellHeight
}

but the problem is that in iPhone X it was doing something like :

on iPhone X Simulator

the bottom part of the bottom item is cut/overlapped. How can I fix it?

Thank you.

Edit :

Thanks for the answer Trupesh Vaghasiya and Pankaj I've done your solution, couldn't find it but this is what I've done {Screenshot}

But the outcome was like this {iPhone X Screenshot}. Don't you think that's violates the iPhone X UI guideline?

Rengers
  • 14,911
  • 1
  • 36
  • 54

3 Answers3

1

You need to change TableView Bottom Constraint First Item Safe Area to give SupperView.

enter image description here

Let us know... is working?

0

Just change your Interface constraint relevant to superView instead of safe area. Check your tableview top and bottom Constraint and make it related to superView. but as per apple said, it is good if you make it related to safe area as iPhone X and higher version have home button on screen so. you can check bellow screen shots. Select Bottom Constraint

enter image description here

Pankaj K.
  • 535
  • 8
  • 18
0

Select constraint that you want to change and Double Click at there.

enter image description here

And then select First Item and then select Superview

enter image description here