如何在UITableView中设置TTStyledTextLabel。每个TTStyledTextLabel都包含一些经过解析的超文本标记语言。
这就是我所知道的,我意识到这可能是完全错误的。
TTStyledTextLabel* label = [[TTStyledTextLabel alloc] autorelease];
cell.textLabel.text = [TTStyledText textFromXHTML:tempString lineBreaks:YES URLs:YES];应用程序在启动时崩溃。我想这是因为我用非文本的内容设置了.text属性。但是,我不知道还可以设置什么。
发布于 2010-11-20 06:57:45
下面的代码将执行您想要的操作。然而,不幸的是,我不知道如何自动设置高度。如果内存不是问题,您可以保留一个单独的TTStyledTextLabels数组并引用它们的高度。
在您的loadView中:
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;
}https://stackoverflow.com/questions/4131230
复制相似问题