iPhone restrict user from entering space in textfield

前端 未结 6 1973
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-05 08:40

i want to restrict user from entering space in a UITextField. for this i m using this code

- (BOOL)textField:(UITextField *)textField shouldChangeCharacters         


        
6条回答
  •  别那么骄傲
    2021-01-05 09:11

    string == @" "
    

    Isn't that just going to compare the adress of each of string and @" "? Thats not the comparison you want to do.

    Also do you want to prevent them from entering a string that is just a space? If so then you need to change that == into a proper string comparison and you are good to go. If not and you want to prevent all spaces in an input string then you need a string matcher

提交回复
热议问题