This is my first time using Three20 and I am trying to add a TTStyledTextLabel to my TTTableViewCell using the following code:
@interface ConvoreCell : TTTableViewCell{
TTStyledTextLabel * tt_title;
UITextView * title;
UILabel * detailed;
}
@property (nonatomic, retain) IBOutlet UITextView * title;
@property (nonatomic, retain) IBOutlet UILabel * detailed;
@property (nonatomic, retain) TTStyledTextLabel * tt_title;
@end
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self == [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
tt_title = [[TTStyledTextLabel alloc] init];
tt_title.font = [UIFont systemFontOfSize:15];
[self.contentView addSubview:tt_title];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect frame = tt_title.frame;
frame.size.width = 640;
frame.size.height = tt_title.text.height;
frame.origin.x = 45;
frame.origin.y = 5;
tt_title.frame = frame;
}
and in my TTTableView I have:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat titleHeight = [TTStyledText textFromXHTML:[[self.posts objectAtIndex:indexPath.row] message] lineBreaks:YES URLs:YES].height;
//NSLog(@"HEIGHT IS %f", titleHeight);
return titleHeight + 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ConvoreCell";
ConvoreCell *cell = (ConvoreCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[ConvoreCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
TTImageView * avatar = [[TTImageView alloc] initWithFrame:CGRectMake(cell.frame.origin.x+5, cell.frame.origin.y+5, 40, 40)];
avatar.urlPath = [[[self.posts objectAtIndex:indexPath.row] creator] img];
avatar.userInteractionEnabled = YES;
avatar.tag = indexPath.row;
[cell addSubview:avatar];
cell.tt_title.text = [TTStyledText textFromXHTML:[[self.posts objectAtIndex:indexPath.row] message] lineBreaks:YES URLs:YES];
}
However, the layout is messy as hell. Why is this?

I cannot find anything wrong with your code.
Looking at the image, what strikes me is that the last row which is correcly displayed contains a link.
What I suspect is that it could be some bug in
TTStyledText, which in my experience is not really suitable for displaying full HTML.Could you try and confirm (or dismiss) this hypothesis? Is always so that a url in a row will make it “go crazy”?
In any case, it will help to set a breakpoint on (or an
NSLogafter) the lineand check what is going in
cell.tt_title.text.