Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide empty cells in UITableView

I have a searchable tableview, but would like to only display the number of cells that are returned once a user starts a search. For instance, if a user types in a charecter and there is only one cell that matches the search, the remaining cells the remaining cells of the table are empty. I was wondering if there is a way to hide those empty cells. I was also wondering if there is a way to hide the table view if a person's search does not match any data (by default, it displays a table of empty cells saying "No Results").

Thanks.

like image 297
minimalpop Avatar asked Jul 14 '10 17:07

minimalpop


3 Answers

Set the tableFooterView to some dummy view ([[UIView new] autorelease] will work fine). This prompts the UITableView to show the footer (which will have zero size) in place of the empty 'cells'.

like image 66
TomSwift Avatar answered Nov 18 '22 21:11

TomSwift


- (void) viewDidLoad
{
  [super viewDidLoad];
 *// self.tableView.tableFooterView = [[[UIView alloc] init] autorelease];*   
  *//Since memory management is controlled by ARC now, so ignore autorelease*
  self.tableView.tableFooterView = [[UIView alloc] init] ;
}
like image 23
yunas Avatar answered Nov 18 '22 22:11

yunas


Change your implementation of tableView:numberOfRowsInSection: in your data source to return the number of search results instead of the total number of items. Then populate those cells with the search results instead of with the rest of the data.

like image 5
Carl Norum Avatar answered Nov 18 '22 23:11

Carl Norum