我不确定这是否是一条好的路线,...我从网上收到的一些数据反过来填充了一个表视图。问题是,文本是html(p标签等)。我的第一个想法是在单元格中创建一个uiwebview,并使用loadHTMLString填充。事实上,它是KINDA的作品。但是,我那时细胞不再是接触的接受者。

所以,在我们深入了解代码之前,有没有比使用UIWebView更好的方法来填充单元格。感觉就像一个黑客,我担心,即使它有效,苹果也会把它转走。

//来自我的自定义UITableViewCell类:

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
    [self setFrame:frame];

    webcell = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,frame.size.width-20,frame.size.height)];
    [self.contentView addSubview:webcell];

    //bloack the webview from touches
    UIView *cover = [[UIView alloc] initWithFrame:webcell.frame];
    [self.contentView addSubview:cover];
    [cover release];
}
return self;

}

- (void)setLabelData:(FeedItem *)feedItem {     link = feedItem.link;

NSMutableString *htmlstring = [NSMutableString string];
[htmlstring appendString:@"<html><head><link rel='stylesheet' href='style.css'/></head><body>"];
[htmlstring appendFormat:@"<p>%@</p>",feedItem.title];
[htmlstring appendFormat:@"<p>%@</p>",feedItem.description];
[htmlstring appendString:@"</body></html>"];
[webcell loadHTMLString:htmlstring baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]];

}

感谢

有帮助吗?

解决方案

除非有人在那里有反驳,否则我认为UITableViewCell中的UIWebView不是一个好主意。虽然,我还没有测试过本地的htmlString ......

其他提示

我们在单元格中使用webview取得了一些成功。如果您希望单元格接收触摸事件,则需要将webview的userInteractionEnabled属性设置为NO。您还需要为每个单元格使用不同的reuseIdentifier,因为webview需要一些时间来加载其内容,并且可能在它准备好之前重用。

我已经通过静态分配webview-cells完成了这个,我知道我需要多少表格,并启动它们全部加载到屏幕外。没有重用标识符,您需要跟踪单元格以及它们自己的位置。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top