问题描述
如何在 UITableView 中设置 TTStyledTextLabel.每个 TTStyledTextLabel 包含一些解析的 HTML.
How can I set a TTStyledTextLabel inside of a UITableView.Each TTStyledTextLabel contains Some parsed HTML.
这是我所拥有的,我意识到它可能完全错误.
Heres what I have I realize its probably completely wrong.
TTStyledTextLabel* label = [[TTStyledTextLabel alloc] autorelease];
cell.textLabel.text = [TTStyledText textFromXHTML:tempString lineBreaks:YES URLs:YES];
应用在启动时崩溃.我认为这是因为我正在使用非文本的内容设置 .text 属性.但是,我不知道还要设置什么.
App Crashes on launch. I think its because I am setting the .text property with something that is not text. However, I don't know what else to set.
推荐答案
以下代码将满足您的需求.不幸的是,我无法弄清楚如何自动设置高度.如果内存不是问题,您可以保留一个单独的 TTStyledTextLabels 数组并参考它们的高度.
The following code will do what you want. Unfortunately, however, I cannot figure out how to automatically set the height. If memory isn't an issue you could keep a seperate array of TTStyledTextLabels and reference their heights.
在您的加载视图中:
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;
}
这篇关于在 UITableView 中显示 TTStyledTextLabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!