Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove empty cells in UITableView? [duplicate]

i am trying to display a simple UITableView with some data. I wish to set the static height of the UITableView so that it doesn't displays empty cells at the end of the table. how do I do that?

code:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {      NSLog(@"%d", [arr count]);     return [arr count]; } 
like image 253
z22 Avatar asked Jan 25 '13 10:01

z22


People also ask

How do I delete a cell in UITableView?

So, to remove a cell from a table view you first remove it from your data source, then you call deleteRows(at:) on your table view, providing it with an array of index paths that should be zapped. You can create index paths yourself, you just need a section and row number.

Which code is correct for removing extra lines from tableView?

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.


2 Answers

Set a zero height table footer view (perhaps in your viewDidLoad method), like so:

Swift:

tableView.tableFooterView = UIView() 

Objective-C:

tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; 

Because the table thinks there is a footer to show, it doesn't display any cells beyond those you explicitly asked for.

Interface builder pro-tip:

If you are using a xib/Storyboard, you can just drag a UIView (with height 0pt) onto the bottom of the UITableView.

like image 146
Andy Avatar answered Sep 22 '22 18:09

Andy


Swift 3 syntax:

tableView.tableFooterView = UIView(frame: .zero) 

Swift syntax: < 2.0

tableView.tableFooterView = UIView(frame: CGRect.zeroRect) 

Swift 2.0 syntax:

tableView.tableFooterView = UIView(frame: CGRect.zero) 
like image 33
Dustin Williams Avatar answered Sep 22 '22 18:09

Dustin Williams