Question

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.

Was it helpful?

Solution

You should implement

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

delegate method. and return 100.0 there.

OTHER TIPS

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;

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.

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).

The better and cleaner solution is to implement the delegate function (Maybe not the best one if your UITableView has many rows ...).

Also, think that UITableVieCell are UIView so you could change their height firstly...

Delegates are very powerful in iPhone dev, here the UITableViewDelage:

http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html

You can also change the indentForRow, displayCellForRow, heightForRow,edit stuff .....

I dont think there is such a method in UITableView...

Instead you can use the property rowHeight...
Try, tableView.rowHeight =100;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top