iPhone + UITableView + row height
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).
Related videos on Youtube
Comments
-
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 over 11 yearsIt matters WHEN you set row height
-
-
Epsilon Prime over 14 yearsActually it's in UITableViewDelegate.
-
Nidhin Paul over 14 yearsCareful. Pratik didn't say he wanted per-row height. heightForRowAtIndexPath can be expensive with a lot of rows.
-
Sahil about 14 yearsproperties 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 about 13 yearsThis 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 almost 13 yearsThis 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 almost 13 yearsif all the cells have the same row height, setting rowHeight is much more efficient than using this delegate method.