Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Results - UITableView iPhone

I'm trying to display a no results message on my tableview when it is empty. I have done the uilabel approach where it appears when it is empty but it seems like it's not how Apple has done it in the Contacts etc where the "No Results" move as well when you try to scroll up and down. Mine just stays there in one spot.

Does anyone know how to do this?

I think they added a No Results cell?

like image 993
K.Honda Avatar asked May 31 '11 08:05

K.Honda


1 Answers

Yes. If you have no results to display, do the following

  1. Create a boolean flag named noResultsToDisplay, or something else.
  2. If you have no results to display then set noResultsToDisplay = YES, set it to NO otherwise.
  3. In numberOfRowsInSection, if (noResultsToDisplay) return 3;
  4. In cellForRowAtIndexPath, if (noResultsToDisplay && indexPath.row == 2) cell.textLabel.text = @"No Results";
like image 156
EmptyStack Avatar answered Sep 29 '22 16:09

EmptyStack