Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove empty cells from UITableView? [duplicate]

I have a UITableView with cells having data from server response which means not everytime all the cells displays the data. So I need to remove those "empty" cells.I have already searched and could not find any possible solution. The solution from How to remove empty cells in UITableView? didn't work out. Actually it made my tableview disappear.

I need another solution other than the addition of a footer view. Is there any?

like image 978
hamedazhar Avatar asked Dec 08 '22 19:12

hamedazhar


2 Answers

You should check your data which is coming from the server and only add not nil data to tableview data source.

After that reload your tableview.

This way your tableview won't have any empty cells. simple.

In case your problem is that number of cell being displayed doesn't fill up your view

you can try

tableview.tableFooterView = UIView()
like image 157
rv7284 Avatar answered Dec 10 '22 07:12

rv7284


You can use one of the two methods.

1. self.tableView.tableFooterView.frame = CGRectZero;
2. self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
like image 25
Dinu Avatar answered Dec 10 '22 08:12

Dinu