yeforriak
yeforriak

Reputation: 1715

Three20 framework, how to change default row height TTTableView?

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;

Upvotes: 3

Views: 1215

Answers (3)

RyanG
RyanG

Reputation: 4503

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;
}

Upvotes: 0

lyonanderson
lyonanderson

Reputation: 2035

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.

Upvotes: 4

yeforriak
yeforriak

Reputation: 1715

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];}

Upvotes: 0

Related Questions