2010-11-09 89 views
0

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

继承人我有我意识到它可能完全错误。

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

应用程序在启动时崩溃。我认为它是因为我将.text属性设置为不是文本的东西。但是,我不知道还有什么要设置。

回答

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

在你的loadView