how to hide empty rows in a UITableView and change the height of the Uitableview based on non-empty rows

NEW ANSWER

In Swift 2.2, 3.0 and onwards, do the following:

tableView.tableFooterView = UIView()

OLD ANSWER BELOW. KEPT FOR POSTERITY.

If you must use UITableViewStylePlain, and you don’t use a footerView for anything else, you can use the following semi-dirty solution if you have ARC enabled.:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];

    return view;
}

If you have ARC disabled, use the following:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[[UIView alloc] init] autorelease];

    return view;
}

This creates an invisible footerView, that appears immediately after the last data-filled cell.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)