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

前端 未结 11 1867
离开以前
离开以前 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:39
    [self.SomeTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    

    Use this to get rid of the lines if the UITableView is empty.

    0 讨论(0)
  • 2021-01-30 05:39

    A bit hidden in Bourne's answer; if you want to hide to bottom empty rows in a plain tableview with multiple sections, use this answer:

    https://stackoverflow.com/a/5658100/580173

    0 讨论(0)
  • 2021-01-30 05:43

    You sure you are using UITableViewStyleGrouped style?

    Because by default it is set to UITableViewStylePlain which shows empty cells too after displaying filled cells.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-30 05:51

    This can also be done through Interface Builder. Simply add a 1 pixel tall UIView as a footer to the UITableView. It's essentially the same as most of the answers here, but it keeps some UI specifics in the view instead of in the view controller.

    enter image description here

    0 讨论(0)
提交回复
热议问题