2

いくつかのテーブルビューセルを含むテーブルビューがあります。テーブルビューセルは、タイトル(UILabelを使用)、画像(UIWebViewを使用)、および要約(UITextViewを使用)で構成されます。

画像にUIImageを使用すると、すべてが正常に実行されます。しかし、その後、UIImageの代わりにサイズ変更されたUIWebViewを使用して写真を表示することにしました。UITextViewの要約の一部が予期せず変更されます。

テーブルをスクロールすると、問題が解決することがあります。ただし、別のテーブルビューセルにランダムに再び表示される可能性があります。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

TableViewCell *cell = (TableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
    cell = table;
    self.table = nil;
}

//Configure the cell...

Article *article = [_articleRepository fetchArticleById:[articleIds objectAtIndex:indexPath.row]];
cell.headline.text = article.articleTitle;

// Remove html tag
NSString *substringContent = [self stringByStrippingHTML:article.articleContent];

cell.content.text = substringContent;

cell.selectionStyle = UITableViewCellSelectionStyleGray;

ImageRepository *imageRepository = [[ImageRepository alloc]init];
Image *image = [imageRepository fetchImageById:article.articleImage];

NSMutableString *mutUrl = [[NSMutableString alloc]initWithString:image.imageUrl];
[mutUrl insertString:@"_thumb" atIndex:[mutUrl length]-4];
NSString *stringUrl = [[NSString alloc]initWithString:mutUrl];

NSString *htmlImage = [NSString stringWithFormat:@"<html><head><style type=\"text/css\">body{margin: 0; padding: 0;}</style></head><body><img src=\"%@\"></body></html>", stringUrl];


[cell.image loadHTMLString:htmlImage baseURL:nil];

return cell;

}

4

1 に答える 1

0

問題がセル全体にランダムに表示されるのは、テーブルビュー内のセルの再利用が原因である可能性があります。あなたが行ったことのコードを投稿した場合に役立ちます。
編集:コードの部分を以下のように変更してみてください。

if (cell == nil) {

    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
    cell = [topLevelObjects objectAtIndex:0];
}

いくつかの質問: 1. なぜ cell = table & self.table = nil を行うのですか?

于 2012-12-04T06:36:59.253 に答える