【发布时间】:2017-02-06 07:21:34
【问题描述】:
我是 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>&#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;
}
如何解决这个问题。 提前致谢!
【问题讨论】:
-
无法理解您的问题。
-
@InderKumarRathore 从 Web 服务我得到了一些 HTML 格式的文本,例如 用于在问题中使用代码。但我面临的问题是文本没有以正确的 HTML 格式显示。
-
@InderKumarRathore 我在这样的数组中获得价值“
”我不想再活在谎言中了。当我 10 岁的时候,我妈妈在雅典的一家酒店, 希腊。
". -
为什么不使用带有选项 [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType] 的属性字符串来解析 HTML 内容?
-
@Swift_Guru 我可以将它添加到 NSMutableArray 中吗??
标签: html ios objective-c uitableview