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

前端 未结 11 1977
离开以前
离开以前 2021-01-30 05:06

I have couple of problems with my UITableView.

  1. When I add a UITableview on my page, by default it brings up some fixed number of rows,

11条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-30 05:28

    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.

提交回复
热议问题