2014-01-29 31 views
3

我想設置屬性文本作爲「textlabel」在基本的UITableViewCell中的值。 但是,單元格顯示爲空白!這裏是代碼UITableViewCell textLabel歸於文本iOS7

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> 

我不知道如何指定我想要各種「類」ES值。但是,上面的html片段被解析爲一個有效的屬性字符串。

+0

try [[NSMutableAttributedString alloc] initWithString:htmlString] – santhu

+0

沒有幫助,html沒有被解析。 –

+0

而不是使用UILabel,使用交互= NO和scrollEnabled = NO的UIWebView。 – santhu

回答

0

我測試了你的代碼,看起來你的html字符串有問題。

我試着將htmlString設置爲@「<div>Test</div>」,它工作。但是,當我在標籤中包裝「測試」時,它將不再可見。

希望這會幫助你解決它。

P.S .:另外,儘量不要在tableView:cellForRowAtIndexPath:方法中分配對象。它可以真的減慢你的滾動。

+0

好吧,我試着將它設置爲一些基本的html @「test」。那也行不通。另外,雖然我在'tableView:cellForRowAtIndexPath'中分配單元格。我正在使用動態原型,這是來自蘋果的推薦代碼。我也嘗試過

。相同的結果。空的tableview單元格。 –

+0

將它包裝在

中。 – Arcanfel

+0

我試圖修改的UITableViewCell原型說,爲textLabel歸屬,但這並沒有幫助 –

相關問題