Eliminate Extra Separators Below Uitableview

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

Sample Image


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

Eliminating extra separator lines for empty rows in UITableView in Swift

UIView inherits init() from NSObject, that why it's valid and doesn't give any error. Every class in Cocoa(Touch) that works with Objective-C inherits from this class (maybe except NSProxy). And it's clear that UIView has it's frame property default to CGRectZero that why it still does work.

I would say you always go with init(frame:) since it's Designated Initializer for UIView. And it gives a clearer intent to the reader. By using init(), you can't be sure that all the properties will be more properly set than using init(frame:).

Update

After having done some little experiment, I found out that UIView.init() calls UIView.init(frame:) by passing CGRectZero. So, I would say that both are totally equivalent. But, I would still suggest you use init(frame:) since it can express a clearer intent to the reader. But that's up to your style.

Here's the code:

@interface MyView : UIView

@end

@implementation MyView

- (instancetype)init; {
self = [super init];
if (self) {
NSLog(@"%s", __FUNCTION__);
}
return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
NSLog(@"%s | %@", __FUNCTION__, NSStringFromCGRect(frame));
}
return self;
}

@end

And by calling [[MyView alloc] init]; it prints:

-[MyView initWithFrame:] | {{0, 0}, {0, 0}}
-[MyView init]

Update

Here's the Swift version:

class MyView: UIView {
override init() {
super.init()
println(__FUNCTION__)
}

override init(frame: CGRect) {
super.init(frame: frame)
println("\(__FUNCTION__) | \(frame)")
}

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
println(__FUNCTION__)
}
}

Then you just call MyView() somewhere in your code.

Hide remove separator line if UITableViewCells are empty

You can hide UITableView's standard separator line by using any one of the below snippets of code.
The easiest way to add a custom separator is to add a simple UIView of 1px height:

UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
separatorLineView.backgroundColor = [UIColor clearColor]; // set color as you want.
[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

And also check nickfalk's answer, it is very short and helpful too.
And you should also try this single line,

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

Not sure but it's working in all the version of iOS that I checked, with iOS 5 and later, up to iOS 7.

Remove UITableView separator line

Objective-C :

[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

Swift:

self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None

Swift 5.0 renamed it in :

self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none

Apply the line in viewDidLoad() method.

If you want to do it from nib file, set the tableView's Separator property to None

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

Sample Image


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

Can I force a UITableView to hide the separator between empty cells?

You can achieve what you want by defining a footer for the tableview. See this answer for more details:Eliminate Extra separators below UITableView

How to remove cell separators in UITableView?

  1. Check your layout of cell,especially top and bottom constraints.Sample Image
  2. Check the content view of cell.Did you set the clips to bounds to true?Sample Image
    Sample Image

All the above should be checked both in code and IB.

Remove Separator from Grouped UItableview

Thanks All,

Have solved this by setting Bottom Constraint of the view to -1, and unchecked Clip To Bounds for both UITableViewCell and its Content View.

Table view cells unwanted excess separator lines

add These codes to your .m file:

-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.tableView.tableFooterView =[[UIView alloc] initWithFrame:CGRectZero]; //set your tableView's tableFooterView
}


Related Topics



Leave a reply



Submit