Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand correctly, you'd like a way of showing a 'no data to display' message if there are no results, and then replace that when data is available.</p> <p>My approach is generally to display a loading indicator (overlaid over the table view) to the user when I start loading the content (i.e. when first making the call to the server). You can have a flag on your controller that tracks whether you're currently loading data - set this to YES when you start loading, and then NO when loading completes. While loading, you can simply not display any cells in your table (assuming you have some other display to show the user that it's loading). E.g.</p> <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (isLoading) return 0; //Don't display any cells while loading if (modelArray.count == 0) return 1; //1 row for the cell indicating there's no data return modelArray.count; //1 row for each entry in array } </code></pre> <p>When the server returns data, remove the loading indicator and refresh the table view data.</p> <p>When no data is returned, presumably your model array will be empty. Simply check for this case in the <code>tableView:cellForRowAtIndexPath:</code> in your UITableViewDataSource, and if the array is empty, return a cell with a message indicating that there's no data, e.g.</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (modelArray.count == 0) { return noResultsMessageCell; } else { &lt;normal cell dequeueing code&gt; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload