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

后端 未结 10 1536
余生分开走
余生分开走 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:42

    swift 2:

    if (string.characters.count == 0 && range.length == 1) {
                return true
    }
    

    you should use like this string.characters.count

提交回复
热议问题