gpt4 book ai didi

ios - UITableViewCell textLabel attributedText iOS7

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:40:22 25 4
gpt4 key购买 nike

我正在尝试将属性文本设置为基本 UITableViewCell 中“textlabel”的值。但是,单元格显示为空白!这是代码

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

// Configure the cell...
NSDictionary *docattr = [NSDictionary new];
NSError *myerror = [NSError new];
NSString *htmlString = [[[dm latestUpdates] objectAtIndex:indexPath.row] objectForKey:@"display_data"];
NSMutableAttributedString *updateText =
[[NSMutableAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding]
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]}
documentAttributes:&docattr
error:&myerror];

[cell.textLabel setAttributedText:updateText];
// cell.detailTextLabel.attributedText = updateText;
NSLog(@"cell text %@", cell.textLabel.text);
// cell.textLabel.text = htmlString;
return cell;

以上代码将我的 html 转换为有效的属性字符串。但没有显示任何内容。有问题的 html 是

<div class='title'><a href='mc://guru_txn/171'>Wilbur Ross bought EXCO Resources, Inc.</a></div><div class='description'>Wilbur Ross bought 19,599,973 shares of EXCO Resources, Inc. (<a href='mc://quotes/XCO'>XCO</a>) @ $5.00 per share on 2014-01-17.</div>

我不知道如何指定我想要的各种“类”的值。但是,上面的 html 片段被解析为有效的属性字符串。

最佳答案

我已经测试了你的代码,你的 html 字符串似乎有问题。

我尝试将 htmlString 设置为 @"<div>Test</div> ",它起作用了。但是,当我将“test”包裹在标签中时,它就不再可见了。

希望这能帮助您解决问题。

P.S.:另外,尽量不要在tableView:cellForRowAtIndexPath中分配对象: 方法。它确实会减慢您的滚动速度。

关于ios - UITableViewCell textLabel attributedText iOS7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21440845/

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