[英]Display A TTStyledTextLabel in a UITableView
How can I set a TTStyledTextLabel inside of a UITableView. 如何在UITableView中设置TTStyledTextLabel。 Each TTStyledTextLabel contains Some parsed HTML.
每个TTStyledTextLabel都包含一些已解析的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];
App Crashes on launch. 应用在启动时崩溃。 I think its because I am setting the .text property with something that is not text.
我认为是因为我将.text属性设置为不是文本的内容。 However, I don't know what else to set.
但是,我不知道还要设置什么。
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.
如果内存不是问题,则可以保留一个单独的TTStyledTextLabels数组并引用其高度。
in your loadView: 在您的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];
in your class: 在您的课程中:
-(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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.