Remove empty space before cells in UITableView

后端 未结 30 1745
生来不讨喜
生来不讨喜 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:05

    Swift 5

    Try with remove tableHeaderView and tableFooterView

    var frame = CGRect.zero
    frame.size.height = .leastNormalMagnitude
    tblView.tableHeaderView = UIView(frame: frame)
    tblView.tableFooterView = UIView(frame: frame)
    
    0 讨论(0)
  • 2020-11-30 17:06

    Check your tableview frame in storyboard or xib. Mine by default has a y position value, hence the bug

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

    I am doing this programmatically, and I simply moved my addSubview(tableView) to the bottom after adding all of my other subviews, and it solved my problem!

    Not sure why this only appears on device and not my simulator, but either way at least there is a simple solution!

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

    UIView can be inserted at the top and bottom of the table(drag and drop). Set their properties as transparent and height of 1 px. This is to remove the extra padding in front of the cells.

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

    I also had this problem the tableView wasn't the last view in the hierarchy. In my case i had a view above (even though they were not overlapping each other), so i dragged it above the tableView in the hierarchy and that made it.

    0 讨论(0)
  • I can't say for sure but it looks like you've got an extra UIView stuck between where the Prototype Cells begin and the top of the UITableView. My image looks exactly like yours if you remove the text/lines I added in.

    enter image description here

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