gpt4 book ai didi

ios - 类型 'ChatViewController' 没有成员 'showOrHideKeyboard'

转载 作者:搜寻专家 更新时间:2023-11-01 06:55:52 25 4
gpt4 key购买 nike

我好像找不到我做的函数。

Error: Type 'ChatViewController' has no member 'showOrHideKeyboard'

代码:

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
NotificationCenter.defaultCenter.addObserver(self, selector: #selector(ChatViewController.showOrHideKeyboard(_:)), name: UIKeyboardWillShowNotification, object: nil)
NotificationCenter.defaultCenter.addObserver(self, selector: #selector(ChatViewController.showOrHideKeyboard(_:)), name: UIKeyboardWillHideNotification, object: nil)
}

@IBOutlet weak var contraintToBottom: NSLayoutConstraint!

func showOrHideKeyboard(notification: NSNotification) {
if let keyboardInfo: Dictionary = notification.userInfo {
if notification.name == UIResponder.keyboardWillShowNotification {
UIView.animate(withDuration: 1, animations: { () in
self.contraintToBottom.constant = (keyboardInfo[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue.height
self.view.layoutIfNeeded()
}) { (completed: Bool) -> Void in
//
}
}
}
}

最佳答案

你应该用objc标记选择器方法

改变这一行

func showOrHideKeyboard(notification: NSNotification) {
}

到这一行

@objc func showOrHideKeyboard(_ notification: NSNotification) {
}

关于ios - 类型 'ChatViewController' 没有成员 'showOrHideKeyboard',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53424389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com