Reputation: 979
I am new in iOS and I am facing problem regarding to add HTML content in NSMutableArray in UITableView.
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>&#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>"I don'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
- (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!
Upvotes: 0
Views: 300
Reputation: 1340
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
Upvotes: 1