I have three separate “UIViewControllers” in my app. Each has UITableView attached to it.
- First UITableView displays just a single table of rows of data (news items).
- Second UITableView displays a search view, which has a few sections where users type in different search criteria.
- Third UITableView displays the article details.
In each of the UITableView, there is a button.
- First UITableView has “Load more articles” button.
- Second UITableView has “Search” button
- Third UITableView has “Visit article page” button.
Since all three views are UITables, I created a custom UITableCellView and added to each of the UITableViews. Here’s an example of my “ButtonCell” in the 2nd UITableView
ButtonCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ButtonCell"];
NSString *cellText = @"Search";
[[cell buttonLabel] setText:cellText];
return cell;
This works well – exactly how I want it.
Now I added the same “ButtonCell” to the first and third UITableView, but a few strange things happened.
-
The background color of the ButtonCell is not correct – in the ButtonCell “.xib” file, I set it to a blue-ish color. This works well for the 2nd UITableView, but for others, it’s just “white”.
-
The ButtonCell doesn’t have “rounded corners” anymore.
Any ideas on how to properly “re-use” my custom button cell in any UITableViews?
It sounds like your second table is grouped, and the other two plain (you get rounded corners with a grouped table view style). Setting the color of custom cells in IB for plain tables doesn’t work. You should set the color of your cells in the tableView:willDisplayCell:forRowAtIndexPath: delegate method: