I had exactly the same problem, except for half the implementation path, we decided to abandon the design and instead switched to user-defined table cells. Our original design should have looked like a notepad with cells on each line.
Subclassing UITableViewCell may seem like a daunting task, but it's worth it if you need to configure the camera in the future and it looks like it will do what you request. I can post the code for you from my project if you're interested. However, keep in mind that you will not have a background on the UITableView itself, only on the cells.
EDIT: sending code related to creating a custom UITableViewCell: My cell is called HotOffersCell, This is HotOffersCell.h
HotOffersCell.m is very simple, just sysnthesize for all properties, nothing more. Then in the TableView method of your table view controller:
// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"HotOffersCell"; HotOffersCell *cell = (HotOffersCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"HotOffersCell" owner:nil options:nil]; for (id currentObject in topLevelObjects) { if ([currentObject isKindOfClass:[UITableViewCell class]]) { cell = (HotOffersCell *) currentObject; break; } } } NewsItem *newsItem = [newsList objectAtIndex:indexPath.row]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"d MMM YY"]; NSString *date = [formatter stringFromDate:newsItem.departure_date]; if (indexPath.row % 2 == 0) { cell.contentView.backgroundColor = [UIColor colorWithWhite:230.0/255 alpha:1]; // Match Colour } else { cell.contentView.backgroundColor = [UIColor colorWithWhite:242.0/255 alpha:1]; // Match Colour } cell.mainLabel.text = newsItem.destination; cell.subLabel.text = [[NSString alloc] initWithFormat:@"%@ - %@ nights", date, newsItem.nights]; if ([self.navigationController.title isEqualToString:@"Top 20"]) { cell.price.text = newsItem.price_inside; } else { cell.price.text = newsItem.price_balcony; } cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png", newsItem.cruise_line]]; [formatter release]; return cell; }
I also have HotOffersCell.xib. This file contains a UITableViewCell and there is no view, I linked all the corresponding shortcuts and nothing else. It provides a convenient graphical way to edit placements on a label without changing the code, I will even let my brother change this =)
I hope this helps
source share