z22 z22 - 1 month ago 10
iOS Question

How to remove empty cells in UITableView?

i am trying to display a simple

with some data. I wish to set the static height of the
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];


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


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

Swift 2.0:

tableView.tableFooterView = UIView()

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

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