首页 > 解决方案 > 无法解决“发送到实例的无法识别的选择器”消息

问题描述

我正在尝试创建一个在按下按钮时将其当前标题替换为属性字符串的操作。但是,这会导致“无法识别的选择器发送到实例”错误。我已将一个 IBAction 连接到此按钮,并创建了一个引用它的 IBOutlet 弱变量。据我所知,这些不应相互干扰。

这是我连接到按钮的操作的代码

     @IBAction func voButtonTapped(_ sender: Any) {
          let voString = "vo"
          let attributedvo = NSAttributedString(string: voString, attributes: underlineAttribute)
          vButton.setAttributedTitle(attributedvo, for: .normal)
}        

这是下面的错误:

[__SwiftValue set]:无法识别的选择器发送到实例 0x600001584510

下划线属性:

let underlineAttribute: [NSAttributedString.Key: Any] = [
    .font: UIFont(name: "Rockwell-Bold", size: 35) as Any,
    .foregroundColor: ColorManager.specialYellow,
    .underlineStyle: NSUnderlineStyle.single.rawValue]

按钮:

    @IBOutlet weak var vButton: UIButton!

颜色管理器:

struct ColorManager {
  static let specialYellow = Color("Special Yellow")

}

标签: swiftxcodexcode11ibactionunrecognized-selector

解决方案


colorManager 结构导致了这个问题。

我不得不改变它

   static let specialYellow = Color("special yellow")

   static let specialYellow = UIcolor(red: 0.85, green: 0.68, blue: 0.00, alpha: 1.00)

所以基本上我不能使用我原来保存的颜色,不得不从一个六角托盘中找到一个类似的颜色,然后我使用一个在线转换器将它转换为 UIcolor


推荐阅读