My UITableView get data off the internet. Sometimes it doesn't receive any (cell) data. It just shows a blank table.
How can I show a message/cell to the user that no data records have been found?
My UITableView get data off the internet. Sometimes it doesn't receive any (cell) data. It just shows a blank table.
How can I show a message/cell to the user that no data records have been found?
You can add a test in your -tableView:cellForRowAtIndexPath: implementation and display a special UITableViewCell saying "no results available" when you get no data.
Another approach, which generally looks better, is to add a custom view to the UITableView directly. Don't forget to remove it when there are results to display.
You want to return one cell reporting on the lack of data.
If you're keeping your cell data in an array that's a class property (let's say NSArray *listings
), you can go:
-(NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
if ([self.listings count] == 0) {
return 1; // a single cell to report no data
}
return [self.listings count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.listings count] == 0) {
UITableViewCell *cell = [[[UITableViewCell alloc] init] autorelease];
cell.textLabel.text = @"No records to display";
//whatever else to configure your one cell you're going to return
return cell;
}
// go on about your business, you have listings to display
}