how to remove empty cells in uitableview

how to remove empty cells in uitableview  using -'ios,objective-c,uitableview'

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?


- (NSInteger)tableView:(UITableView *)tableView
             numberOfRowsInSection:(NSInteger)section {
    NSLog(@"%d", [arr count]);
    return [arr count];


asked Oct 13, 2015 by sameer rathore
0 votes

5 Answers

0 votes

Set a zero height table footer view, like so:

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.

answered Oct 13, 2015 by rajeevr642
0 votes

Edit: My original answer was completely wrong, apologies.

Please set an empty footer view (as suggested by Andy), as so:

tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
answered Oct 13, 2015 by loknath.ganji
0 votes

I can not add comment as of now so adding this as an answer.

@Andy's answer is good and the same results can be achieved with the following line of code:

tableView.tableFooterView = [UIView new];

'new' method belongs to NSObject class and invokes alloc and init methods for UIView.

answered Oct 13, 2015 by patilkiran.101
0 votes

Implemented with swift on Xcode 6.1

self.tableView.tableFooterView = UIView(frame: CGRectZero)
self.tableView.tableFooterView?.hidden = true

The second line of code does not cause any effect on presentation, you can use to check if is hidden or not.

Answer taken from this link Fail to hide empty cells in UITableView Swift

answered Oct 13, 2015 by badhwar.rohit
0 votes

I tried the code:

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

In the viewDidLoad section and xcode6 showed a warning. I have put a "self." in front of it and now it works fine. so the working code I use is:

self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
answered Oct 13, 2015 by kinnari