首页 > 解决方案 > 将项目从 swift 4 转换为 swift 5 时,“ViewController”类型的值错误没有成员“keyboardDidShow(notification:)”

问题描述

将项目从Swift 4转换为Swift 5时,类型值错误ViewController没有成员。下面是现在给出错误的代码keyboardDidShow(notification:)

 NotificationCenter.default.addObserver(self, selector:#selector(self.keyboardDidShow(notification:)), name: UIResponder.keyboardDidShowNotification, object: nil)

标签: iosswift

解决方案


添加方法实现

class ViewController:UIViewController {
    override func viewDidLoad() {
      super.viewDidLoad()
      NotificationCenter.default.addObserver(self, selector:#selector(self.keyboardDidShow(notification:)), name: UIResponder.keyboardDidShowNotification, object: nil)
   }
   @objc func keyboardDidShow(notification:NSNotification) {}
}

vc里面


推荐阅读