我如何使用#selector?

时间:2016-08-22 19:45:26

标签: ios swift nsnotificationcenter

如何将这些语句转换为使用#selector语句。 这些语句工作正常但在Xcode中发出警告,我不喜欢。

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil)

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil)

1 个答案:

答案 0 :(得分:3)

在Swift 3中,它看起来像这样:

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