2

below I have a picture attached of a uitableview I am using numberOfRowsInSection to return data.count however more rows show up than are in the count, and I only have one section. So why do the extra rows show up? If I have a tableview as the only subview of the main content view I do not have this problem, but I have another view on the same level in the view hierarchy as the uitableview.

enter image description here

user3832583
  • 371
  • 4
  • 19
  • 1
    Possible duplicate of [How to remove empty cells in UITableView?](http://stackoverflow.com/questions/14520185/how-to-remove-empty-cells-in-uitableview) – Sam B Mar 19 '17 at 00:30

2 Answers2

7

UIKit does not create the empty rows when the tableView has a footerView displayed below the table cells. You can add one with zero height. So, Its not visible to the user. In the viewDidLoad method of your tableView .Create a new UIView with a zero rect frame and use it to set the tableFooterView property of the tableView:

yourTableViewName.tableFooterView = UIView(frame: CGRect.zero)
Joe
  • 8,868
  • 8
  • 37
  • 59
1

In my case, they are separation lines, this happens when you set the table height greater than the content height, one thing you can do is set your separator to "None" or you can set the tableView height close to the height of your content.

Greetings, hope this help someone.

Paul3k
  • 166
  • 1
  • 4