iPhone : Hiding empty tables cells in a plain view table
I cant seem to work out how to hide table cells that have no data. In grouped view, you only get a cell per piece of data. Whereas in plain view, it renders the cells to the bottom of the screen. I sure its possible because the world clock does it
Irrespective of the type of table, it'll fill up the space allocated to it in Interface Builder (or whatever frame is assigned, etc. if you're creating it programatically).
What you might want to do is set the background as transparent (using the "Clear Color" option as the Background color in the Interface Builder) and use a custom cell background, which is what I believe the world clock does.
To do this, just implement the background in the table cell returned within the tableView:cellForRowAtIndexPath: method by creating a view and using the setBackgroundView and setSelectedBackgroundView methods on the UITableViewCell appropriately.
To get this World Clock Effect I've set a background image for the UITableView background and put the table background color to clearColor via:
UIImage *image = [UIImage imageNamed:@"background.png"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; [imageView setFrame:self.tableView.bounds]; [self.tableView setBackgroundView:imageView]; [imageView release]; [self.tableView setBackgroundColor:[UIColor clearColor]];
To get rid of the separators I've changed the separator style to none via
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
For the UITableViewCell I set a background color (here: white):
UIView *cellBackgroundView = [[UIView alloc] init]; [cellBackgroundView setBackgroundColor:[UIColor whiteColor]]; [cell setBackgroundView:cellBackgroundView]; [cellBackgroundView release];