A: 

Generally I have been using multiple view controllers when I display table views. I use a UIViewController subclass to controller the whole view and any bars or buttons (anything not table view related). Then I create a UITableViewController to control only the table.

This has several effects:

First, it allows me to encapsulate behavior much better. The UITableViewController is much cleaner and portable.

Second, you get a real UIView to deal with issues like the problem you are having. It seems like more work, but allows greater customization. You can do whatever you want for the background.

Third, It allows me to use a XIB for the main view much easier, without worrying about the UITableView content (which may be network loaded or not, or have other loading issues).

So my suggestion, would be your first solution. But you should do this all the time, not just when you think you will need the additional flexibility. That way it is already in place.

Corey Floyd
A: 

Just put in your Tableview and search bar inside a UIView (make the UITableViewController a UIViewController) and set the view background to the color you want either in IB or in code.

lostInTransit
+6  A: 

There is a delegate method called -tableView:willDisplayCell:forRowAtIndexPath: that can be used to customize the background color of the cell after the table view has made it's modifications. From the UITableViewDelegate reference:

A table view sends this message to its delegate just before it uses cell to draw a row, thereby permitting the delegate to customize the cell object before it is displayed. This method gives the delegate a chance to override state-based properties set earlier by the table view, such as selection and background color. After the delegate returns, the table view sets only the alpha and frame properties, and then only when animating rows as they slide in or out.

Also, since the background color peeks out from the bottom of the table when trying to scroll past the last cell, I had to create a footer view and update the table view's content inset:

UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
footerView.backgroundColor = [UIColor whiteColor];
self.tableView.tableFooterView = footerView;
[footerView release];

UIEdgeInsets inset = self.tableView.contentInset;
inset.bottom = 44 - footerView.frame.size.height;
self.tableView.contentInset = inset;
Martin Gordon
This is the best solution I've found so far, but there must be a cleaner way. The footer means that normal "empty cells" wont appear in your tableView. The empty space will be flat white (or whatever colour you've chosen). The inset.bottom doesn't need the extra 44 pixels either. That will leave a blank gutter at the bottom of the tableView. inset.bottom = -footerView.frame.size.height makes the "bottom" of the tableView the last row.When using the "Fade" animation style for deleting cells you will see a flash of colour as the cell vanishes. So always use "Top" or "Bottom" etc.
Ryan Booker
It dawned on me this morning. There is a simpler and cleaner solution. Instead of all the hoop jumping of changing colors and setting cell backgrounds, just create a tableHeaderView similarly to the footView described above, that contains the searchBar.Works perfectly. No muss. No fuss. It still seems like a hack solution, though. Just a smaller hack.
Ryan Booker
A: 

Hi Mr.Martin,

I am having exactly the same problem. I am trying to change the color of Gutter, but it does changing the set color for the entire table itself instead of only Gutter. I don't know how to make it resolved? I mean, i don't know how to provide some color only on Gutter and it shouldn't affect anything on the Table. Could you please explain the solution quickly as i'm in need of some urgency to have fix this?

thanks.

Clave/

Clave Martin
A: 

Any solution please? I need steps clearly and sample source if any..?

Clave Martin