2017-09-07 86 views
1

我想用NSAttributed字符串加下劃線。出於某種原因,我行導致異常:設置NSUnderlineStyle導致無法識別的選擇器異常

-[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance 

結果應該被用於一個UITableView內一個UILabel,並根據需要創建。

這是代碼:

attributedString = NSMutableAttributedString(string: message) 

if let actor = event.actor { 
    let attributes = [NSUnderlineStyleAttributeName:NSUnderlineStyle.styleSingle] 
    var attributedActorString = NSMutableAttributedString(string: actor.shirtName, attributes: attributes) 
    attributedActorString.insert(NSAttributedString(string: " "), at: 0) 
    attributedActorString.append(NSAttributedString(string: ". "))        attributedActorString.append(attributedImageStringForUrl(event.actor!.portraitImageUrl, indexPath: indexPath)) 
    attributedString.append(attributedActorString) 
} 

回答

3

更改行:

let attributes = [NSUnderlineStyleAttributeName:NSUnderlineStyle.styleSingle] 

到:

let attributes = [NSUnderlineStyleAttributeName:NSUnderlineStyle.styleSingle.rawValue] 
+0

這奏效了我!謝謝。 – ff10

+0

@ ff10,歡迎您;] –

相關問題