Before ios 5 I would set the row height in a tableview like this:
self.tableView.rowHeight=71;
However, it doesn't work on iOS5.
Someone has an idea?
Thanks
Have you tried tableView:heightForRowAtIndexPath:
from UITableViewDelegate
?
You may set the row height to 71 by implementing tableView:heightForRowAtIndexPath:
in your UITableView
delegate (one who supports the UITableViewDelegate
protocol).
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 71.0;
}
First you should set a delegate of your tableView. Delegate should conform to the UITableViewDelegate
protocol. Let's say we have a TableDelegate
class. To conform to a UITableViewDelegate
protocol one should have it in square brackets in it's declaration like this:
...
@interface TableDelegate : UIViewController <UITableViewDelegate>
...
or
@interface TableDelegate : UIViewController <some_other_protocol, UITableViewDelegate>
Then you set the delegate:
...
// create one first
TableDelegate* tableDelegate = [[TableDelegate alloc] init];
...
self.tableView.delegate = tableDelegate;
In the end you should implement the tableView:heightForRowAtIndexPath:
method in the TableDelegate
implementation:
@implementation TableDelegate
...
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 71.0;
}
...
@end
Just to clarify, using rowHeight
should work just fine and perform better than constant returned from -tableView:heightForRowAtIndexPath:
as Javier Soto points out in the comments. Also note, that if your UITableView has delegate returning height in -tableView:heightForRowAtIndexPath:
and rowHeight
property set, prior value is honoured.
Im coding for iOS 5 and it actually works. You just need to implement the line you said in the:
- (void)viewDidLoad
method after the:
[super viewDidLoad];
The:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
method does not work if the TableView is empty. But if you use the rowHeight property it will work even if the view is empty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With