gpt4 book ai didi

objective-c - UITextView 中的字体大小意外更改

转载 作者:行者123 更新时间:2023-12-01 16:53:38 24 4
gpt4 key购买 nike

我有一个带有几个表格 View 单元格的表格 View 。表格 View 单元由标题(使用 UILabel)、图片(使用 UIWebView)和摘要(使用 UITextView)组成。

当我将 UIImage 用于图片时,一切运行良好。但后来,我决定使用调整大小的 UIWebView 而不是 UIImage 来显示图片。 UITextView 中的一些摘要意外更改。

当我滚动表格时,问题有时会消失。但它可以再次随机出现在不同的表格 View 单元格上。

- (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;
}

最佳答案

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

if (cell == nil) {

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

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

关于objective-c - UITextView 中的字体大小意外更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13697303/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com