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

Hi I have a TableViewController with two static cells, however when displayed it shows two static cells and then all the other empty cells for the table. However, I do not want to display these cells as they are useless. How to hide other cells separately from two static cells?

+53
ios swift tableview
Feb 24 '15 at 23:45
source share
7 answers

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

 tableView.tableFooterView = UIView() 
+199
Feb 24 '15 at 23:48
source share

To add to this, the reason why setting tableFooterView - UIView() delete rows is because you are setting an empty UIView() object for the property. According to Apple documentation:

 var tableFooterView: UIView? 

Therefore setting an empty UIView () does not display anything below your data for this property.

You can return empty rows by resetting tableFooterView to the default value, for example:

 tableView.tableFooterView = nil 
+4
Sep 28 '16 at 10:08
source share

You can achieve this also in Storyboard by simply dragging the view into the footer area of ​​the table, and then set its height and background color to 1 and clear accordingly using the Property inspector.

(It is assumed that you either cannot or don’t just want to use the group style setting for some reason. Otherwise, just do it.)

+2
Feb 02 '17 at 6:15
source share
 tableView.tableFooterView = UIView.init(frame: CGRect.zero) 

Call this code inside the viewWillAppear method. And will work

+1
Feb 02 '17 at 7:37
source share

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

+1
Apr 24 '17 at 20:57
source share

Just add:

 tableView.tableFooterView = UIView() 

Explanation:

This is absolutely correct and works great in fast 3.By. Since you are setting an empty UIView () object for a property, setting tableFooterView to UIView () removes the rows.

0
Apr 12 '17 at 6:46 on
source share

I tried tableview.tableFooterView = UIView () and this did not work for me. That is why I use my own TableViewViewCell.

I found hack tho. In my func numberOfRowsInSection

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return yourArrayClass.count - 1 } 

And that makes my extra empty custom UITableViewCell no longer appear. Of course, this is superfluous empty. I will check it out a bit more by adding more cells. For reference, I use Swift 3, Firebase, a custom cell class, inside the cellForRowAt function.

0
Jun 23 '17 at 19:39 on
source share



All Articles