swift – 设置NSUnderlineStyle会导致无法识别的选择器异常

前端之家收集整理的这篇文章主要介绍了swift – 设置NSUnderlineStyle会导致无法识别的选择器异常前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图用NSAttributed字符串为字符串加下划线.由于某种原因,我的行导致异常:
-[_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)
}
换线:
let attributes = [NSUnderlineStyleAttributeName:NSUnderlineStyle.styleSingle]

至:

let attributes = [NSUnderlineStyleAttributeName:NSUnderlineStyle.styleSingle.rawValue]
原文链接:https://www.f2er.com/swift/319156.html

猜你在找的Swift相关文章