I am using a TTListDataSource to populate a TTTableViewController.
This is the code I am using to populate the TTListDatSource items array:
NSString *text = [NSString stringWithFormat:@"<b>%@</b><br/>%@", someObject.title, someObject.text];
TTStyledText *styledText = [TTStyledText textFromXHTML:text lineBreaks:YES URLs:YES];
[items addObject:[TTTableStyledTextItem itemWithText:styledText]];
I would like to change the default row height the TTTableView is using, currently 2 lines height.
any ideas how can I do that?
I've tried using these properties in few parts of my code with no luck:
TTTableViewController.variableHeightRows = YES;
TTStyledText.setNeedsLayout;
TTStyledText sizeToFit;
If you use variableHeightRows then in your table cell classes you need to implement:
+ (CGFloat)tableView:(UITableView*)tableView rowHeightForObject:(id)object;
Beware that using variableHeightRows
will cause the framework to go through your entire datasource calling this method to get the overall height of the table. If all your rows are the same height then in your TTTableViewController subclass in loadView
your should set the rowHeight
property of the tableView.
I answer myself here.
One solution is to override the initWithNibName method of the TTTableViewController as follows:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
self.variableHeightRows = YES;
}
return self;
}
A second approach is to use TTTableViewDragRefreshDelegate as the delegate of your TTableViewController. This delegate sets variableHeightRows as true.
- (id<UITableViewDelegate>)createDelegate {
return [[[TTTableViewDragRefreshDelegate alloc] initWithController:self] autorelease];}
Solution for me:
I just moved those 2 lines into the viewDidLoad method; that worked for me!
- (void)viewDidLoad
{
self.title = @"E-Mail";
self.variableHeightRows = YES;
}
来源:https://stackoverflow.com/questions/5007271/three20-framework-how-to-change-default-row-height-tttableview