我剛剛更改了我的tableview以閱讀豐富文本而不是純文本,所以我的解決方案是將豐富文本加載到UIWebview中,然後將webview添加到tableview單元格contentview。 但是,通過此更改,文本不再顯示。下面是-cellForRowAtIndexPath代碼:UITableView中的UIWebView丟失文本
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellTVIdentifier = @"CellTVIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellTVIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellTVIdentifier]
autorelease];
}
int row = indexPath.row;
NSString *cellString = [theArray objectAtIndex:row];
// replaced cell.textLabel.text=cellString;
// with
UIWebView *webTVCell = [[UIWebView alloc] init];
[webTVCell loadHTMLString:cellString baseURL:nil];
[cell.contentView addSubview:webTVCell];
[webTVCell release];
return cell;
然而,在cellString文本不再出現在tableview中的任何細胞。任何人都可以幫忙嗎?這將非常感激。
工作正常!謝謝!但現在仍然存在一個問題:我在-heightForRowAtIndexPath中調整了每個單元的大小,因此tableview單元具有合適的高度。但是webview只顯示大約一半的內容;我可以向下滾動到文本的其餘部分,但它隱藏在單元格的底部。有沒有辦法讓webview填充每個單元格的內容,而不是滾動?謝謝你的幫助。 – Namhcir
[webTVCell setScalesPageToFit:YES]; –
將文本的大小設置得很小,以至於無法閱讀;另外,我設置了tableviewcells的背景顏色,但是文本區域是灰色的,其餘的單元格是我指定的顏色。 – Namhcir