首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在UITableView中显示TTStyledTextLabel

在UITableView中显示TTStyledTextLabel
EN

Stack Overflow用户
提问于 2010-11-09 15:06:24
回答 1查看 745关注 0票数 0

如何在UITableView中设置TTStyledTextLabel。每个TTStyledTextLabel都包含一些经过解析的超文本标记语言。

这就是我所知道的,我意识到这可能是完全错误的。

代码语言:javascript
复制
TTStyledTextLabel* label = [[TTStyledTextLabel alloc] autorelease];
cell.textLabel.text = [TTStyledText textFromXHTML:tempString lineBreaks:YES URLs:YES];

应用程序在启动时崩溃。我想这是因为我用非文本的内容设置了.text属性。但是,我不知道还可以设置什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-20 06:57:45

下面的代码将执行您想要的操作。然而,不幸的是,我不知道如何自动设置高度。如果内存不是问题,您可以保留一个单独的TTStyledTextLabels数组并引用它们的高度。

在您的loadView中:

代码语言:javascript
复制
CGRect cgRct2 = CGRectMake(0, 35, 320, 375); //define size and position of view 
    tblView = [[UITableView alloc] initWithFrame:cgRct2 style:UITableViewStylePlain];
    tblView.dataSource = [self constructDataSource];
    tblView.delegate = self;
    //[tblView reloadData];
    [myView addSubview:tblView];

在你的班上:

代码语言:javascript
复制
-(TTListDataSource *)constructDataSource {
    NSLog(@"constructDataSource");
    NSMutableArray * namesArray = [[NSMutableArray alloc] init];

    //ADD ITEMS
    [namesArray addObject:[TTStyledText textFromXHTML:[NSString stringWithString:@"some XHTML"]]];




    TTListDataSource * dataSource = [[TTListDataSource alloc] init];
    for (int i = 0; i < [namesArray count]; i++) {
        TTStyledText * text = [namesArray objectAtIndex:i];

        [dataSource.items addObject:[TTTableStyledTextItem itemWithText:text]];
    }

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

https://stackoverflow.com/questions/4131230

复制
相关文章

相似问题

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