2009-09-17 91 views
0

我不知道這是否是一個好的路線去...我有一些數據,我從網上接收,反過來,填充表視圖。問題是,文本是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]]]; 

}

感謝

回答

0

,除非有人在那裏有rebuttle,我的結論是,在一個UITableViewCell一個UIWebView是不是一個好主意。儘管如此,我還沒有測試過本地htmlString ...

0

我們已經在單元格中使用webviews取得了一些成功。如果您希望單元格接收觸摸事件,則需要將webview的userInteractionEnabled屬性設置爲NO。您還需要爲每個單元格使用不同的reuseIdentifier,因爲webview需要一些時間才能加載其內容,並可能在準備好之前重新使用。

0

我已經完成了靜態分配的webview單元格,只要我知道我需要多少桌子,並啓動它們全部加載離屏。沒有重用標識符,您需要跟蹤單元格以及它們自己的位置。