Swift NSNotificationCenter?

后端 未结 1 1980
醉话见心
醉话见心 2021-01-26 08:11

I\'m trying to get the UITextViewTextDidChangeNotification to work. I\'m new to using the NSNotificationCenter, so I\'m having a hard time understanding what\'s going on exactly

相关标签:
1条回答
  • 2021-01-26 08:59

    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) {
    
    }
    
    0 讨论(0)
提交回复
热议问题