0

I have a UITableView below a UITextField. Strangely, the upper part of the UITableView has a white background. The tableView scrolls nicely till just below the UITextField, so it is being placed correctly below it. It is just that the upper portion is somehow getting a white background. And this portion seems to scale with respect to the height of the UITextField. i.e. if I increase the height of the textField, the white portion will increase too.

I have tried setting the adjust scroll view insets to false but to no avail.

enter image description here

enter image description here

Gavin
  • 2,784
  • 6
  • 41
  • 78
  • 3
    http://stackoverflow.com/questions/27827315/empty-white-space-above-uitableview-inside-a-uiview –  Feb 28 '17 at 03:23
  • Check the last answer also, make sure you have not accidentally added some header to your tableView inside storyboard. –  Feb 28 '17 at 03:24
  • I have tried the suggested answers there. Mine is a little different. The tableView display properly. It is sitting just right below the textField, but the background of the upper portion is white. I have checked that there was no header under the tableView in storyboard. – Gavin Feb 28 '17 at 03:31
  • If you look at the screenshot, the spacing is the exact height as the UINavigationController. I would guess that you have some wierd hierarcy with multiple navigationControllers. Make sure you are pushing/presenting this UIViewController correctly. If this solves your issue let me know I will update as the answer since I don't find something similiar. I answered something like this before but I cant find the post unfortunately. –  Feb 28 '17 at 03:34
  • There is actually no spacing. Just white background, and it scales along with the `UITextField`'s height at the top. – Gavin Feb 28 '17 at 03:36
  • What happens if you remove the UITextField and simply constraint the uitableview to the top of the superView? –  Feb 28 '17 at 03:37
  • You could run the application and check in the debug view hierarchy what exactly is happening! – Rikh Feb 28 '17 at 05:09
  • @MaTaKazer remove your text field and add it as `tableview header` – Gokul G Feb 28 '17 at 06:56

3 Answers3

0

layout and its constraints are looking fine, I think you might have added a header view in code. Can you check your delegate and data source functions in your class.

  • **Do not use answers as comment section** also read the comments below the actual question and you will see your suggestion has already been tested. –  Feb 28 '17 at 05:55
0

Go to storyboard and select view controller where your tableview is and enter image description here enter image description here

Unmark option Adjust ScrollView Insets

  • OP said he has already done that – Rikh Feb 28 '17 at 04:54
  • Give each view different color and then check which view it is ? Otherwise in viewdidload() {//give frame to tableview by setting y = textfield.frame.origin.y + textfield.frame.size.height } – Sahil Arora Feb 28 '17 at 05:00
  • **I have tried setting the adjust scroll view insets to false but to no avail.** –  Feb 28 '17 at 05:57
0

By default an section height and footer of 28 is added to the tableview in xib.

Change it 1 for both header and footer in the size inspector.

tableview section header and height

Zarif Ahmed
  • 343
  • 2
  • 9