gpt4 book ai didi

swift5 - 类型 'NSNotification.Name' 没有成员 'UIResponder'

转载 作者:行者123 更新时间:2023-12-01 22:56:46 25 4
gpt4 key购买 nike

我在 Swift 5 中遇到此错误

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow(_:)), name: NSNotification.Name.UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide(_:)), name: NSNotification.Name.UIResponder.keyboardWillHideNotification, object: nil)

enter image description here

我也遇到了以下错误

“名称”不是“通知”的成员类型

public let ImagePickerTrayDidHide: Notification.Name = Notification.Name(rawValue: "ch.laurinbrandner.ImagePickerTrayDidHide")

我该如何解决这个问题?

最佳答案

正如我最初猜测的那样,您有以下代码:

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)

当您在 Xcode 10.1 中编译它时,您收到以下错误:'keyboardWillShowNotification' 已重命名为 'NSNotification.Name.UIKeyboardWillShow',请将 'keyboardWillShowNotification' 替换为 'NSNotification.Name.UIKeyboardWillShow'并且“keyboardWillHideNotification”已重命名为“NSNotification.Name.UIKeyboardWillHide”,请将“keyboardWillHideNotification”替换为“NSNotification.Name.UIKeyboardWillHide”

然后,您按了两次“修复”,并得到了已添加到问题中的错误代码。您应该使用以下内容:

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)

关于swift5 - 类型 'NSNotification.Name' 没有成员 'UIResponder',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55887777/

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