2014-01-24 77 views
3

我想用HTML字符串填充UITableView。获取字符串,把它们放入单元格等等,一切都很好。我想改变我的NSAttributedText的字体和字体大小。我写了下面的代码。“NSAttributedString initWithData:选项:documentAttribute:错误:”不按预期方式工作

我通过第一个NSLog检查了代码,如果我的UIFont在字典中如预期的那样;所以它在字典中。仍然没有问题。但是我的字体和字体大小在运行时不会改变。没有控制台错误。只是不工作。

第二个NSLog用于检查属性字符串的字体和大小。它说,我的字符串是“Times New Roman”,fontSize:12。但正如你将在代码中看到的,我正在努力使它与尺寸15的“Verdana”

任何人都可以帮助我解决这个问题吗?谢谢。 PS:我在一些对象中保留字符串。 obj.name是我想写入表格单元格的字符串。
Html字符串有一些不需要的标签,所以函数[self clearTheHtml:obj.name]函数正在清除它们。

NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init]; 
    UIFont *font = [UIFont fontWithName:@"Verdana" size:15]; 
    [attributes setObject:font forKey:NSFontAttributeName]; 
    NSString *s = [self clearTheHtml:obj.name]; 
    NSLog(@"%@", [attributes objectForKey:NSFontAttributeName]); //to see if my font is not in the dictionary. 
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[s dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:&attributes error:nil]; 
    NSLog(@"%@", attributedString); 

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2 forIndexPath:indexPath]; 
    cell.textLabel.attributedText = attributedString; 

编辑:

这里是的NSString * S:

2014-01-25 07:38:04.527 KadirB[7483:70b] 
''Narakas 2013 Brachial Plexus Surgery Symposıum'' 23-25 Mayıs 2013 tarihleri arasında Montreux, İsviçre de yapıldı. Brakial Plexus sorunlarına yönelik son gelişmeler toplantıda tartışıldı. 
+0

您能否提供一个存在于“s”中的HTML示例? –

+0

@KendallHelmstetterGelner我编辑并添加了NSString * s ..检查请。我的htmlCleaner会清除