首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在TTTableViewCell中使用TTStyledTextLabel的杂乱布局

在TTTableViewCell中使用TTStyledTextLabel的杂乱布局
EN

Stack Overflow用户
提问于 2011-05-27 02:37:13
回答 1查看 499关注 0票数 0

这是我第一次使用Three20,我正在尝试使用以下代码将TTStyledTextLabel添加到我的TTTableViewCell中:

代码语言:javascript
复制
@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];
}

然而,布局却像地狱一样凌乱。为什么会这样呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-27 03:01:03

我找不到你的代码有任何错误。

看着图像,让我印象深刻的是,正确显示的最后一行包含一个链接。

我怀疑这可能是TTStyledText中的一些错误,根据我的经验,它并不真正适合显示完整的HTML。

你能试着确认(或否定)这个假设吗?总是让一行中的url让它“疯狂”吗?

在任何情况下,在该行上设置断点(或在该行之后设置NSLog )都会有所帮助

代码语言:javascript
复制
 cell.tt_title.text = [TTStyledText textFromXHTML:[[self.posts objectAtIndex:indexPath.row] message] lineBreaks:YES URLs:YES];

并检查cell.tt_title.text中发生了什么。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6143449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档