How to remove extra empty cells in TableViewController, iOS - Swift

后端 未结 13 967
暗喜
暗喜 2020-12-22 16:12

Hi I have a TableViewController with two static cells, however when displayed, it shows the two static cells, and then all the other empty cells for the tablevi

相关标签:
13条回答
  • 2020-12-22 16:23
    tableView.tableFooterView = UIView.init(frame: CGRect.zero)
    

    Call this code in viewDidLoad method.

    0 讨论(0)
  • 2020-12-22 16:24

    You can achieve this also in Storyboard by simply dragging a view into the table view's footer area, and then set its height and background color to 1 and clear respectively using the property inspector.

    (This assumes that you either can't or don't want to just use the Group style setting for some reason. Otherwise, just do that.)

    0 讨论(0)
  • 2020-12-22 16:25

    Simply add:

    tableView.tableFooterView = UIView()
    

    Explanation:

    This is totally valid and works perfectly in swift 3.By Since you are setting an empty UIView() object to the property, Setting tableFooterView to UIView() removes the rows.

    0 讨论(0)
  • 2020-12-22 16:26

    Select your UITableView, go to the attribute inspector and change the style to Grouped.

    0 讨论(0)
  • 2020-12-22 16:27

    in your viewDidLoad() function add this line of code:

    tableView.tableFooterView = UIView()
    
    0 讨论(0)
  • 2020-12-22 16:29

    Abobe anwer is right. We can achieve this by adding

    tableView.tableFooterView = UIView() // to remove extra cells in tableView
    
    0 讨论(0)
提交回复
热议问题