UITextView中的字体大小意外更改

时间:2012-12-04 06:30:59

标签: objective-c ios uitableview uiwebview uitextview

我有一个包含多个表格视图单元格的表视图。表格视图单元格包括标题(使用UILabel),图片(使用UIWebView)和摘要(使用UITextView)。

当我使用UIImage拍照时,一切运行良好。但后来,我决定使用调整大小的UIWebView而不是UIImage来显示图片。 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;

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;

1 个答案:

答案 0 :(得分:0)

这可能是由于在tableview中重复使用单元格会导致问题在单元格中随机出现。如果您发布了已完成的代码,将会有所帮助 编辑:尝试将代码的ur部分更改为下面给出的部分。

if (cell == nil) {

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

一些问题: 你为什么要做cell = table&amp; self.table = nil?

相关问题