iPhone + UITableView + row height

50,673

Solution 1

You should implement

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

delegate method. and return 100.0 there.

Solution 2

You should avoid the heightForRowAtIndexPath if all your rows are of similar height and use the rowHeight property. According to the documentation:

There are performance implications to using tableView:heightForRowAtIndexPath: instead of rowHeight. Every time a table view is displayed, it calls tableView:heightForRowAtIndexPath: on the delegate for each of its rows, which can result in a significant performance problem with table views having a large number of rows (approximately 1000 or more).

In the UITableViewController subclass it could be done, for instance, in the viewDidAppear method (the UITableViewController has a reference to the tableView):

self.tableView.rowHeight = 79.f;

Solution 3

The row height is baked into the cells when they are first displayed.

Did you set UITableView#rowHeight before setting the data source?
If not, do so.
If for whatever reason you can't, your other option is to call UITableView#reloadData after setting the row height.

Solution 4

I did like this, here tableobj is nothing but UITableView object in my application.

- (void)viewDidLoad
{
    [super viewDidLoad];
    [tableObj setRowHeight:100.0f];
}

Or handle it in numberOfRowsInSection: like:

- (NSInteger)tableView:(UITableView *)tblView numberOfRowsInSection:(NSInteger)section {
    [tableObj setRowHeight:100.0f];
    return [soandso count]; // soandso is my object
}

Because set the rowHeight before setting the data source. It worked for me (for equal row heights).

Share:
50,673

Related videos on Youtube

pratik
Author by

pratik

...

Updated on July 09, 2022

Comments

  • pratik
    pratik almost 2 years

    I am setting the row height of my UITableView using following code

    [tableView setRowHeight: 100.00];
    

    I am using the single line as separator in the UITableView.

    Eventhough setting the height above, height of row does not get change.

    • Philip007
      Philip007 over 11 years
      It matters WHEN you set row height
  • Epsilon Prime
    Epsilon Prime over 14 years
    Actually it's in UITableViewDelegate.
  • Nidhin Paul
    Nidhin Paul over 14 years
    Careful. Pratik didn't say he wanted per-row height. heightForRowAtIndexPath can be expensive with a lot of rows.
  • Sahil
    Sahil about 14 years
    properties are just easier ways to access Getters/Setters. doing tableView.rowHeight = 100, is exactly the same as [tableView setRowHeight:100]. getters/setters are automatically created when u synthesize properties.
  • user4951
    user4951 about 13 years
    This is the right though expensive answer: There is one thing that I do not understand. Why the hell Apple insist on knkowing the RowHeight? Why not just ask the Row Height from (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath and get the height from that?
  • jasongregori
    jasongregori almost 13 years
    This solved it for me. Setting rowHeight before I set the data source totally fixed the problem. reloading the data did as well. Thanks emp.
  • jasongregori
    jasongregori almost 13 years
    if all the cells have the same row height, setting rowHeight is much more efficient than using this delegate method.