views:

264

answers:

2

I have a tableview I'd like to customize based on how many rows it has.

If it has no rows, I'd like the background image to prompt the user to add content. If it has 1 or more rows, I'd like it to have a different background image, in order to display the content.

I'm using a fetched results controller to populate my tableview, by the way.

Any ideas?

A: 

I'd recommend taking a look at the documentation for NSFetchedResultsController. It has example code for implementing the methods of UITableViewDataSource (including the ones that say how many sections the table has, and how many rows in each section), as well as documenting the property fetchedObjects, which you could use to see how many raw results you fetched.

[myFetchedResultsController.fetchedObjects count];
Sixten Otto
+1  A: 

I agree with Sixten Otto's answer.

[myFetchedResultsController.fetchedObjects count];

However there's more. Above line would return the number of objects regardless the sections. However if you would want to perform this on a table with multiple sections, you would have to call it the following way.

[[myFetchedResultsController.sections objectAtIndex:<section>] numberOfObjects];

You can get the objects for the section like this.

[[myFetchedResultsController.sections objectAtIndex:<section>] objects];

** You have to replace with the number representing the section.

Hope this helps.

Roshan Amadoru