Swift NSNotificationCenter?

泄露秘密 提交于 2019-12-02 09:36:48

Alright, so I figured out a solution. I needed to post the notification in the textViewDidChange function. I did that using this:

NSNotificationCenter.defaultCenter().postNotificationName("keyPressed", object: nil)

Then I recognized the notification in my viewDidLoad function with this:

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyPressed:"), name:"keyPressed", object: nil);

Then I made this function under my viewDidLoad function:

func keyPressed(sender: NSNotification) {

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!