在uitableview中显示ttStyledTextlabel
-
29-09-2019 - |
题
如何在UitableView的内部设置一个TtStyledTextLabel。每个TTSTYLEDTEXTLABEL都包含一些解析的HTML。
这是我所拥有的,我意识到这可能是完全错误的。
TTStyledTextLabel* label = [[TTStyledTextLabel alloc] autorelease];
cell.textLabel.text = [TTStyledText textFromXHTML:tempString lineBreaks:YES URLs:YES];
启动时应用程序崩溃。我认为这是因为我正在设置.text属性,而不是文本。但是,我不知道该设置什么。
解决方案
以下代码将完成您想要的。但是,不幸的是,我无法弄清楚如何自动设置高度。如果内存不是问题,您可以保留单独的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;
}
不隶属于 StackOverflow