我不知道這是否是一個好的路線去...我有一些數據,我從網上接收,反過來,填充表視圖。問題是,文本是HTML(p標籤等)。我的第一個想法是在單元格中創建一個uiwebview,並使用loadHTMLString填充。事實是,它是KINDA的作品。但是,我當時的細胞不再是觸覺的接受者。因此,在我們深入代碼之前,有沒有比使用UIWebView更好的填充單元格的方法。這感覺就像一個黑客,即使它有效,我也會擔心,蘋果會把它關掉。UIWebView在自定義UITableViewCell
從我的自定義// 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;
}
- (無效)setLabelData:(FeedItem *)feedItem { 鏈路= 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]]];
}
感謝