When I set up a table view with 4 rows, there are still extra separators lines (or extra blank cells) below the filled rows.
How would I remove these cells?
Add a Plain UIView to the Footer of the UITableView First, grab a plain UIView from the object browser, and drag it to the the footer position below all of your cell prototypes. It worked! The separator lines are gone.
To hide UITableViewCell separator completely, simply set it's colour to UIColor. clearColor(). This will make the cell separator not visible.
Just drag a UIView to the table. In storyboard, it will sit at the top below your custom cells. You may prefer to name it "footer".
Here it is shown in green for clarity, you'd probably want clear color.
Note that by adjusting the height, you can affect how the "bottom bounce" of the table is handled, as you prefer. (Height zero is usually fine).
To do it programmatically:
override func viewDidLoad() { super.viewDidLoad() self.tableView.tableFooterView = UIView() }
- (void)viewDidLoad { [super viewDidLoad]; // This will remove extra separators from tableview self.tableView.tableFooterView = [UIView new]; }
or if you prefer,
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
Add to the table view controller...
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { // This will create a "invisible" footer return CGFLOAT_MIN; }
and if necessary...
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [UIView new]; // If you are not using ARC: // return [[UIView new] autorelease]; }
Here's another way to do that w/out the grouped table style, and one you'd probably not guess. Adding a header and footer to the table (perhaps one or the other suffices, haven't checked) causes the separators to disappear from the filler/blank rows.
I stumbled onto this because I wanted a little space at the top and bottom of tables to decrease the risk of hitting buttons instead of a table cell with meaty fingers. Here's a method to stick a blank view in as header and footer. Use whatever height you like, you still eliminate the extra separator lines.
- (void) addHeaderAndFooter { UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)]; v.backgroundColor = [UIColor clearColor]; [self.myTableView setTableHeaderView:v]; [self.myTableView setTableFooterView:v]; [v release]; }
In response to @Casebash, I went back to the code in my app ("AcmeLists" List Manager in iTunes store...) and short-circuited the addHeaderAndFooter method to verify. Without it, I have the extra row separators; with the code, I have what you see in this window snap: no table row separators picture. So I'm not sure why it wouldn't have worked for you. Moreover, it makes sense to me that having any custom footer on a table view would necessarily have to stop drawing row separators for blank rows below it. That would be hideous. For reference, I looked at tables where there were more rows than could be viewed on screen, and then for a table with two rows. In both cases, no extraneous separators.
Perhaps your custom views were not actually added. To check that, set the background color to something other than clearColor
, e.g., [UIColor redColor]
. If you don't see some red bars at the bottom of the table, your footer wasn't set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With