Eliminate extra separators below UITableView

25 Solutions Collect From Internet About “Eliminate extra separators below UITableView”

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:

Swift

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

Objective-C

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

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.

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()
    }

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 🙂

For iOS 7+ using Storyboards

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

Try this. It worked for me:

- (void) viewDidLoad
{
  [super viewDidLoad];

  // Without ARC
  //self.tableView.tableFooterView = [[[UIView alloc] init] autorelease];

  // With ARC, tried on Xcode 5
  self.tableView.tableFooterView = [UIView new];
}

For Swift:

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

If you are using Swift, add the following code to viewDidLoad of the controller that manages the tableview:

override func viewDidLoad() {
    super.viewDidLoad()

    //...

    // Remove extra separators
    tableView.tableFooterView = UIView(frame: CGRectZero)
}

Advancing J. Costa’s solution: You can make a global change to the table by putting this line of code:

[[UITableView appearance] setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];

inside the first poosible method (usually in AppDelegate, in: application:didFinishLaunchingWithOptions: method).

I was using a table view to show a fixed number of columns, so I simply resized it and made it non-scrollable.

I know this Question has be accepted answer but i put here different ways for how to hide Extra separator line of UITableView.

You can hide tableView‘s standard separator line, and add your custom line at the top of each cell.

Update:

The easiest way to add custom separator is to add simple UIView of 1px height:

UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
separatorLineView.backgroundColor = [UIColor grayColor]; /// may be here is clearColor;
[cell.contentView addSubview:separatorLineView];

OR

    self.tblView=[[UITableView alloc] initWithFrame:CGRectMake(0,0,320,370) style:UITableViewStylePlain];
    self.tblView.delegate=self;
    self.tblView.dataSource=self;
    [self.view addSubview:self.tblView];

    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
    v.backgroundColor = [UIColor clearColor];
    [self.tblView setTableHeaderView:v];
    [self.tblView setTableFooterView:v];
    [v release];

OR

- (float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    // This will create a "invisible" footer
    return 0.01f;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    // To "clear" the footer view
    return [[UIView new] autorelease];
}

OR
The best and simple way i like ever is

self.tableView.tableFooterView = [[UIView alloc] init];

Try any of one;

uitableview extra separator line hide extra separators lines hide in swift 3.0

 self.tbltableView.tableFooterView = UIView(frame: .zero)

Just add an view with the desired separator color as background color, 100% width, 1px height at the position x0 y-1 to your tableViewCell. Make sure the tableViewCell doesn’t clip subviews, instead the tableView should.

So you get a absolut simple and working separator only between existing cells without any hack per code or IB.

Note: On a vertical top bounce the 1st separator shows up, but that shouldn’t be a problem cause it’s the default iOS behavior.

You can just add an empty footer at the end then it will hide the empty cells but it will also look quite ugly:

tableView.tableFooterView = UIView()

enter image description here

There is a better approach: add a 1 point line at the end of the table view as the footer and the empty cells will also not been shown anymore.

let footerView = UIView()
footerView.frame = CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 1)
footerView.backgroundColor = tableView.separatorColor
tableView.tableFooterView = footerView

enter image description here

SWIFT 3.0 works great with tableView.tableFooterView = UIView()

If you don’t want any separator after the last cell, then you need a close to zero but non-zero height for your footer.

In your UITableViewDelegate:

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return .leastNormalMagnitude
}

To eliminate extra separator lines from bottom of UItableview programmatically, just write down following two lines of code and it will remove extra separator from it.

tableView.sectionFooterHeight = 0.f;

tableView.sectionHeaderHeight = 0.f;

This trick working for me all the time, try yourself. @KPCoding…

just add this code (Swift) . .

tableView.tableFooterView = UIView()

Try this

self.tables.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 10.0f)];

I had some luck implementing a single piece of the accepted answer (iOS 9+, Swift 2.2). I had tried implementing:

self.tableView.tableFooterView = UIView(frame: .zero)

However, there was no effect on my tableView – I believe it may have something to do with the fact that I was using UITableViewController.

Instead, I only had to override the viewForFooterInSection method (I did not set the tableFooterView elsewhere):

override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    return UIView(frame: .zero)
}

This worked fine for a tableView with a single section (if you have multiple sections, you need to specify the last one).

If you want to remove unwanted space in UITableview you can use below two methods

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}

if you are sub-classing the UITableView you need to do this…

-(void)didMoveToSuperview {
    [super didMoveToSuperview];
    self.tableFooterView = [UIView new];
}

In case you have a search bar in you view (to limit the number of results for example), you have to also add the following in shouldReloadTableForSearchString and shouldReloadTableForSearchScope:

controller.searchResultsTable.footerView = [ [ UIView alloc ] initWithFrame:CGRectZero ];

Details: Swift 3, Xcode: 8.1

Code

extension UITableView {

    var emptyCellsEnabled: Bool {
        set(newValue) {
            if newValue {
                tableFooterView = nil
            } else {
                tableFooterView = UIView()
            }

        }
        get {
            if tableFooterView == nil {
                return true
            }
            return false
        }
    }
}

Usage

// hide empty cells
tableView.emptyCellsEnabled = false

// show empty cells
tableView.emptyCellsEnabled = true

Full example

ViewController.swift

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{

    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var footerSwitchButton: UIButton!

    var emptyCellsEnabled: Bool {
        get {
            return tableView.emptyCellsEnabled
        }

        set (newValue) {
            if newValue {
                footerSwitchButton.setTitle("Hide", for: .normal)
            } else {
                footerSwitchButton.setTitle("Show", for: .normal)
            }

            tableView.emptyCellsEnabled = newValue
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate = self
        tableView.dataSource = self
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell()
        cell.textLabel?.text = "\(indexPath)"
        return cell
    }

    @IBAction func buttonAction(_ sender: Any) {
        emptyCellsEnabled = !emptyCellsEnabled
    }
}

extension UITableView {

    var emptyCellsEnabled: Bool {
        set(newValue) {
            if newValue {
                tableFooterView = nil
            } else {
                tableFooterView = UIView()
            }

        }
        get {
            if tableFooterView == nil {
                return true
            }
            return false
        }
    }
}

Main.storyboard

<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="ABN-e6-xZB">
    <device id="retina4_7" orientation="portrait">
        <adaptation id="fullscreen"/>
    </device>
    <dependencies>
        <deployment identifier="iOS"/>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <scenes>
        <!--View Controller-->
        <scene sceneID="tne-QT-ifu">
            <objects>
                <viewController id="BYZ-38-t0r" customClass="ViewController" customModule="stackoverflow_1633966" customModuleProvider="target" sceneMemberID="viewController">
                    <layoutGuides>
                        <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
                        <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
                    </layoutGuides>
                    <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
                        <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <subviews>
                            <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="Vun-mi-5Wc">
                                <rect key="frame" x="0.0" y="64" width="375" height="603"/>
                                <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                            </tableView>
                        </subviews>
                        <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                        <constraints>
                            <constraint firstItem="Vun-mi-5Wc" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="9Pj-Wl-qW6"/>
                            <constraint firstItem="Vun-mi-5Wc" firstAttribute="bottom" secondItem="wfy-db-euE" secondAttribute="top" id="KIO-bu-Dz6"/>
                            <constraint firstItem="Vun-mi-5Wc" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="gJl-YJ-vQY"/>
                            <constraint firstAttribute="trailing" secondItem="Vun-mi-5Wc" secondAttribute="trailing" id="gef-yl-Rvt"/>
                        </constraints>
                    </view>
                    <navigationItem key="navigationItem" id="tH2-D6-JJL">
                        <barButtonItem key="rightBarButtonItem" style="plain" id="ROj-kP-cCC">
                            <button key="customView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="0C7-jC-HjH">
                                <rect key="frame" x="276" y="7" width="83" height="30"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <state key="normal" title="Button"/>
                                <connections>
                                    <action selector="buttonAction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="d6H-00-Yww"/>
                                </connections>
                            </button>
                        </barButtonItem>
                    </navigationItem>
                    <connections>
                        <outlet property="footerSwitchButton" destination="0C7-jC-HjH" id="EgU-Vx-Skx"/>
                        <outlet property="tableView" destination="Vun-mi-5Wc" id="OHe-J2-y4A"/>
                    </connections>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="1072.8" y="137.18140929535232"/>
        </scene>
        <!--Navigation Controller-->
        <scene sceneID="xgG-0P-k1k">
            <objects>
                <navigationController automaticallyAdjustsScrollViewInsets="NO" id="ABN-e6-xZB" sceneMemberID="viewController">
                    <toolbarItems/>
                    <navigationBar key="navigationBar" contentMode="scaleToFill" id="xS4-8G-RJU">
                        <rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
                        <autoresizingMask key="autoresizingMask"/>
                    </navigationBar>
                    <nil name="viewControllers"/>
                    <connections>
                        <segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="JET-Cj-BFP"/>
                    </connections>
                </navigationController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="Bh9-fJ-Nrf" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="133.59999999999999" y="137.18140929535232"/>
        </scene>
    </scenes>
</document>

Result

enter image description here
enter image description here

I just add this line at the ViewDidLoad function and problem fixed.

tableView.tableFooterView = [[UIView alloc] init];