gpt4 book ai didi

html - 如何在 Objective C 中的 NSMutableArray 中添加 HTML 标签

转载 作者:行者123 更新时间:2023-11-29 00:30:16 27 4
gpt4 key购买 nike

我是 iOS 的新手,我面临着在 UITableView 的 NSMutableArray 中添加 HTML 内容的问题。

我正在使用这样的代码

 namearray=[[NSMutableArray alloc]init];
namearray=[responsedict valueForKey:@"News"];

NSMutableArray *trimmedStrings = [NSMutableArray array];
for (NSString *string in namearray) {
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"<p></p>&amp;#39;"];
NSString *trimmedString = [[string componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];
[trimmedStrings addObject:trimmedString];
}
namearray = trimmedStrings;

但此代码删除标签不添加 HTML 内容。我在这样的数组中获取值 "<p>&quot;I don&#39;t want to live in a lie anymore. When I was 10, my mother in a hotel in Athens, Greece.</p>"

我的单元格行 AtIndexpath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *STI=@"STI";
NewsTableViewCell *cell = (NewsTableViewCell *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:STI];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"NewsTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.accessoryType=UITableViewCellAccessoryNone;
}

NSString *strImgURLAsString = [NewsImageArray objectAtIndex:indexPath.row];
[strImgURLAsString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *imgURL = [NSURL URLWithString:strImgURLAsString];
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:imgURL] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (!connectionError) {
img = [[UIImage alloc] initWithData:data];
if (img==nil) {
img=[UIImage imageNamed:@"userimage.png"];
}
cell.newsimage.image=img;

// pass the img to your imageview
}else{
NSLog(@"%@",connectionError);
}
}];

cell.Headlbl.text=[NSString stringWithFormat:@"%@",[headarray objectAtIndex:indexPath.row]];

cell.bodylbl.attributedText=attrStrBody;


cell.bodylbl.textAlignment=NSTextAlignmentCenter;
cell.bodylbl.textColor=[UIColor whiteColor];
[cell.bodylbl setFont:[UIFont fontWithName:@"Arial" size:16]];
// cell.randrid.text=[NSString stringWithFormat:@"%@",[idarray objectAtIndex:indexPath.row]];
return cell;

}

如何解决这个问题。提前致谢!

最佳答案

NSString *aux = [webServiceArr objectAtIndex:indexPath.row];
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[aux dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSFontAttributeName:font} documentAttributes:nil error:nil];`

在字体属性中设置想要设置的字体

关于html - 如何在 Objective C 中的 NSMutableArray 中添加 HTML 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42062293/

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