skip to Main Content

When I create table view with custom table view, there is empty space between Navigation Bar and the top of Table View.

It looks:
enter image description here

I’ve added constraint to as equal of the view.topAnchor.
I don’t know why is this happening.

How to clip the Table View to the top?

Thank you in advance.

2

Answers


  1. Make sure that you don’t have any header added.
    If you are using a nib/storyboard checkout the ViewController design -> Select tableview -> set Footer height & Header height to 0.

    If you are using code, checkout this example on how to remove the header using code – How to hide first section header in UITableView (grouped style)

    By default it will take 28 that’s why it shows blank on top.

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    

    set above code and make sure delegate method will call.

    Login or Signup to reply.
  2. Try this trick, add to intere view a blank UIView… In viewDidLoad:

    view.addSubview(UIView())
    

    I ignore the reason but this breaks the link between your the UIScrollView and the nav bar… This probably solve your issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search