ios - Swift:访问 Action 处理程序中的 socket 给出 "unrecognized selector sent to instance"

标签 ios swift

在我的 ViewController 中,我有两个 UITextFields,通过 Storyboard/IB 连接为导出:

@IBOutlet weak var textField1: UITextField!
@IBOutlet weak var textField2: UITextField!

我已经为一个 UITextField 连接了“编辑已更改”的操作:

@IBAction func textField1Change(_ sender: UITextField) {
    textField2.text = "Changed"
}

但是,当我在 textField1 中键入内容时,我收到一个 unrecognized selector sent to instance 错误

我什至不能执行 print(textField),这也给了我错误。我做错了什么?

最佳答案

textField1 可能与其他操作有关?检查 textField1 的导出以确保。

或者这样试试:

 func viewDidLoad() {
      super.viewDidLoad()
      textField1.addTarget(self, action: #selector(self.textFieldDidChange), for: .editingChanged)
    }

 func textFieldDidChange(_ textfield: UITextField) {
      textField2.text = "Changed"
    }

关于ios - Swift:访问 Action 处理程序中的 socket 给出 "unrecognized selector sent to instance",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45254148/

相关文章:

ios - 将字符串传递给第二个 View Controller

ios - 添加到视频组合并导出时,叠加图像变得像素化

ios - 基于 Iphone 电话号码格式化语言环境

swift - :texture yields empty result 中的 SKTexture

string - Swift nil 可选字符串 = 空字符串

swift - 如何将 UITableView 从 nib 文件加载到父 View Controller 中的容器 View 中?

ios - 如何在不干扰以前的 pod 的情况下安装 pod?

iOS:如何在我的应用程序中设置铃声和警报音量

ios - 使用 Parse 类数据填充表格 View 单元格

ios - View 不会像在 Storyboard 中那样出现在 iPhone 上