pratik
pratik

Reputation: 4479

iPhone + UITableView + row height

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.

Upvotes: 22

Views: 50718

Answers (6)

Mallikarjun
Mallikarjun

Reputation: 181

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

Upvotes: 3

Morion
Morion

Reputation: 10860

You should implement

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

delegate method. and return 100.0 there.

Upvotes: 65

jokkedk
jokkedk

Reputation: 2390

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;

Upvotes: 23

eBuildy
eBuildy

Reputation: 89

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

Upvotes: 0

emp
emp

Reputation: 3478

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.

Upvotes: 7

Dhanesh
Dhanesh

Reputation: 1141

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

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

Upvotes: -6

Related Questions