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

前端 未结 11 1986
离开以前
离开以前 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条回答
  •  萌比男神i
    2021-01-30 05:50

    in the method that returns the number of rows, specify the count yourself dynamically. For example if you are going to populate the table with say a NSArray named arrayForRows:

    return [arrayForRows count]; // inside the method which returns the number of rows.
    

    The above is a simple example populating a table with an array as a datasource. There are no empty rows. Only that many rows show up in the table according to the count of items in the array populating the table.

    I think you mean height of the row in the table. You can play around with the height of the rows by using the method:

    (CGFloat)tableView:(UITableView  *)tableView heightForRowAtIndexPath:(NSIndexPath  *)indexPath
    

    read http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UITableViewDelegate/tableView:heightForRowAtIndexPath:

    EDIT: ah now I get what you are trying to achieve. You are trying to avoid showing the empty rows separated with those separator lines right? See this post:

    how to display a table with zero rows in UITableView

提交回复
热议问题