Iphone TTTableViewCell中的TTStyledTextLabel布局混乱
这是我第一次使用Three20,我正在尝试使用以下代码将TTStyledTextLabel添加到我的TTTableViewCell中:Iphone TTTableViewCell中的TTStyledTextLabel布局混乱,iphone,objective-c,three20,Iphone,Objective C,Three20,这是我第一次使用Three20,我正在尝试使用以下代码将TTStyledTextLabel添加到我的TTTableViewCell中: @interface ConvoreCell : TTTableViewCell{ TTStyledTextLabel * tt_title; UITextView * title; UILabel * detailed; } @property (nonatomic, retain) IBOutlet UITextView * tit
@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];
}
然而,布局非常混乱。为什么会这样?
我找不到您的代码有任何错误 看这张图片,让我印象深刻的是,正确显示的最后一行包含一个链接 我怀疑这可能是
TTStyledText
中的某个bug,根据我的经验,它并不真正适合显示完整的HTML
你能试着证实(或否定)这个假设吗?总是这样,一行中的url会让它“发疯”
在任何情况下,在该行上(或之后)设置断点都会有所帮助
cell.tt_title.text = [TTStyledText textFromXHTML:[[self.posts objectAtIndex:indexPath.row] message] lineBreaks:YES URLs:YES];
并检查
cell.tt_title.text中的内容
是什么让它变得凌乱?最后一排?为什么它是空的(没有文字)?这就是为什么它凌乱的原因。。应该有一个文本在那里,因为某些原因,它没有调整大小和其他一切后,第六行没有一个文本