How to detect delete key on an UITextField in iOS 8?

后端 未结 10 1543
余生分开走
余生分开走 2020-11-30 00:56

I have subclassed UITextField and implemented the UIKeyInput protocol\'s deleteBackward method to detect backspace being pressed. This works fine on iOS 7 but not on iOS 8.<

10条回答
  •  醉话见心
    2020-11-30 01:51

    Swift 2.2:

    func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
    
        if text == "" {
          print("Backspace has been pressed")
        }
    
        return true
    }
    

提交回复
热议问题