swift - 无法解决“发送到实例的无法识别的选择器”消息
问题描述
我正在尝试创建一个在按下按钮时将其当前标题替换为属性字符串的操作。但是,这会导致“无法识别的选择器发送到实例”错误。我已将一个 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")
}
解决方案
colorManager 结构导致了这个问题。
我不得不改变它
static let specialYellow = Color("special yellow")
至
static let specialYellow = UIcolor(red: 0.85, green: 0.68, blue: 0.00, alpha: 1.00)
所以基本上我不能使用我原来保存的颜色,不得不从一个六角托盘中找到一个类似的颜色,然后我使用一个在线转换器将它转换为 UIcolor
推荐阅读
- firebase - Flutter 应用程序作为 .apk 工作,但使用 firebase 分发“安装失败”
- spring - Spring + Websockets + STOMP + Broker + Gateway 无法扩展
- apache-kafka-connect - Debezium Kafka 连接器 mongodb:将 kafka 连接器连接到 mongodb 时出错
- javascript - 为什么行为不同?
- ocr - Tesseract OCR 将 g 混淆为 9
- amazon-web-services - 哪种 AWS IAM 委托人以 AROA 开头?
- python - 在python中捕获全局变量值的变化
- c# - Visual Studio 2017 c# 将数据导出到 Excel
- python - 我可以使用绘图函数作为图形布局模板并使用其他自定义绘图函数填充子图吗?
- node.js - 超级账本作曲家是否支持多线程?