Remove empty space before cells in UITableView

后端 未结 30 1748
生来不讨喜
生来不讨喜 2020-11-30 16:39

I am currently trying to put a UITableView in a different location rather than at the top of my view controller. With this said, it is trying to add the header

相关标签:
30条回答
  • 2020-11-30 17:25

    Was having the same issue. I solved it by adding the following to viewDidLoad.

    self.extendedLayoutIncludesOpaqueBars = true
    
    0 讨论(0)
  • 2020-11-30 17:28

    In my case I was using a container view.(Main View --> Contaner View --> UITableView)

    The extra space at the top, I think, is like space of the device notification bar (where the time is displayed, the battery). I really do, it's not an assumption.

    What I did was from the UI Builder:

    • select the Table View Controller complete
    • Open Attributes inspector
    • Go to -> View Controller -> Layout -> "Select Wants Full Screen"
    0 讨论(0)
  • 2020-11-30 17:29

    In my case, i was using ContainerViewController and putting UITableViewController in it. After removing ContainerViewController. Issues goes away.

    0 讨论(0)
  • 2020-11-30 17:30

    In 2017, what is working for me is simply this one line

    navigationController?.navigationBar.isTranslucent = false

    I have no idea why that would even affect it. Perhaps someone could explain. But I'm pretty sure this is the answer most people would look for.

    0 讨论(0)
  • 2020-11-30 17:31

    NONE of the above helped me. but doing this did help:

    self.tableView.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0)
    

    instead of '-64' you can put any other number depending on the height of your navigation bar.

    0 讨论(0)
  • 2020-11-30 17:31

    As long as UITableView is not the first subview of the view controller, the empty space will not appear.

    Solution: Add a hidden/clear view object (views, labels, button, etc.) as the first subview of the view controller (at the same level as the UITableView but before it).

    0 讨论(0)
提交回复
热议问题