ios - Eliminate extra separators below UITableView

ID : 2326

viewed : 181

Tags : iosuitableviewcocoa-touchios

Top 5 Answer for ios - Eliminate extra separators below UITableView

vote vote


Interface builder (iOS 9+)

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).

enter image description here

To do it programmatically:


override func viewDidLoad() {     super.viewDidLoad()     self.tableView.tableFooterView = UIView() } 


iOS 6.1+

- (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]; 

Historically in iOS:

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]; } 
vote vote


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.

vote vote


Removing extra separator lines for empty rows in UITableView in Swift

override func viewDidLoad() {     super.viewDidLoad()     // Do any additional setup after loading the view, typically from a nib.     self.yourTableview.tableFooterView = UIView() } 
vote vote


I would like to extend wkw answer:

Simply adding only footer with height 0 will do the trick. (tested on sdk 4.2, 4.4.1)

- (void) addFooter {     UIView *v = [[UIView alloc] initWithFrame:CGRectZero];      [self.myTableView setTableFooterView:v]; } 

or even simpler - where you set up your tableview, add this line:

//change height value if extra space is needed at the bottom. [_tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectMake(0,0,0,0)]]; 

or even simplier - to simply remove any separators:

[_tableView setTableFooterView:[UIView new]]; 

Thanks to wkw again :)

vote vote


For iOS 7+ using Storyboards

Simply drag a UIView into your UITableView as the footer. Set the footer view's height to 0.

Top 3 video Explaining ios - Eliminate extra separators below UITableView