0

How can I hide row lines of UITableView from those rows, what are not used. For example, look at screenshot:

enter image description here

Can I show just 4 lines and hide other lines what are not used? So, I show just 4 lines and further comes white screen, not lines as now

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Orkhan Alizade
  • 7,379
  • 14
  • 40
  • 79

4 Answers4

2

do like set your tableFooterView frame as CGRectZero on viewDidLoad

override func viewDidLoad() {

super.viewDidLoad()

// set as your tableFooterView frame as CGRectZero it hides the empty rows
self.tableView.tableFooterView = UIView(frame: CGRectZero)

self.tableView.backgroundColor = UIColor.clearColor()

}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
2
//Obj-c code    
    TableName.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
//Swift code
    tableView.tableFooterView = UIView(frame: .zero)

Use this code to hide the extra row lines.

Put this code in ViewDidLoad or in ViewWillApper

GameLoading
  • 6,688
  • 2
  • 33
  • 57
0
  • Gave snippets in Objective-C should be same in Swift as well

In your viewDidLoad Method include

self.localTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

In viewDidLayoutSubViews include

-(void)viewDidLayoutSubviews
{
    if ([self.localTableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.localTableView setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([self.localTableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.localTableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

In tableView willDisplyCell delegate method include

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

here localTableView is the outlet taken from storyboard

harsha yarabarla
  • 506
  • 4
  • 11
0

// Swift 3

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.tableFooterView = UIView(frame: .zero) }
Mayuri R Talaviya
  • 613
  • 1
  • 9
  • 14