0

如何在 UITableView 中设置 TTStyledTextLabel。每个 TTStyledTextLabel 都包含一些已解析的 HTML。

这是我所拥有的,我意识到它可能完全错误。

TTStyledTextLabel* label = [[TTStyledTextLabel alloc] autorelease];
cell.textLabel.text = [TTStyledText textFromXHTML:tempString lineBreaks:YES URLs:YES];

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

4

1 回答 1

0

以下代码将执行您想要的操作。然而不幸的是,我无法弄清楚如何自动设置高度。如果内存不是问题,您可以保留一个单独的 TTStyledTextLabels 数组并参考它们的高度。

在您的负载视图中:

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

在你的课堂上:

-(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;
}
于 2010-11-19T22:57:44.687 回答