UITableView - How to show rows only which contains data

11,578

Solution 1

You can set a footer view and make it invisible if you want. Separators will appear only for rows which contain data:

self.theTableView.tableFooterView = [[[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 10.0f)] autorelease];

Solution 2

Try this ..

self.tableView.tableFooterView = [UIView new];

Solution 3

I don't think it is possible to hide the extra separators using a standard way. This behavior is preset.

Plain styled tableView shows the row/separator even if there are no real rows exist. Only Grouped styled tableView shows only the existing rows.

Edit: As suggested by others, you can add a footer view to tableView to hide those extra separators.

Share:
11,578
nitesh meshram
Author by

nitesh meshram

Updated on June 13, 2022

Comments

  • nitesh meshram
    nitesh meshram almost 2 years

    How can i show UITableView Rows only which contains data not the other rows. By default UITableView shows 10 rows. If we have data for three rows It will display three rows only How can I implement this? Thank you.

  • ValentinaMotta
    ValentinaMotta almost 13 years
    if "data" is your Array/Dictionary with data you can return [data count];
  • albertamg
    albertamg almost 13 years
    you can eliminate the extra separators by adding a footer view to the table.