简体   繁体   English

如何在目标c中的NSMutableArray中添加HTML标签

[英]How to add HTML Tags in NSMutableArray in objective c

I am new in iOS and I am facing problem regarding to add HTML content in NSMutableArray in UITableView. 我是iOS的新手,并且遇到有关在UITableView的NSMutableArray中添加HTML内容的问题。

I am using code like this 我正在使用这样的代码

 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;

But this code remove tag not adding HTML content.I am getting value in array like this "<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>" 但是这段代码删除了标签,没有添加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>"这样的数组中获得了价值, "<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>"

My cell for row AtIndexpath 我的行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;

} 

How to solve this issue. 如何解决这个问题。 Thanks in Advance! 提前致谢!

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

set font which you want to set in font attribute 在字体属性中设置要设置的字体

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM