Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide empty rows in a UITableView and change the height of the Uitableview based on non-empty rows

I have couple of problems with my UITableView.

  1. When I add a UITableview on my page, by default it brings up some fixed number of rows, even though I set number of rows in section as 1. All the rows appear except the first row, and all are empty rows. So, I want to hide all the empty rows in the UItableview.

  2. Based on the non-empty rows, I want to change the height of my UItableView.

like image 990
sbmandav Avatar asked Nov 18 '10 09:11

sbmandav


1 Answers

NEW ANSWER

In Swift 2.2, 3.0 and onwards, do the following:

tableView.tableFooterView = UIView()

OLD ANSWER BELOW. KEPT FOR POSTERITY.

If you must use UITableViewStylePlain, and you don't use a footerView for anything else, you can use the following semi-dirty solution if you have ARC enabled.:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {     UIView *view = [[UIView alloc] init];      return view; } 

If you have ARC disabled, use the following:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {     UIView *view = [[[UIView alloc] init] autorelease];      return view; } 

This creates an invisible footerView, that appears immediately after the last data-filled cell.

like image 89
ArtSabintsev Avatar answered Nov 16 '22 00:11

ArtSabintsev