Adel
Adel

Reputation: 411

Removing the leading whitespace from the first word in UITextField

I have a tableview where the last row is UITextField and where the user is supposed to type a first and last name.

What I would like to do is to remove or restrict any whitespace before the first name (first word). Next, I would like to allow the user to use whitespace. How can I do that?

Thank you in advance.

Upvotes: 1

Views: 688

Answers (1)

abdus.me
abdus.me

Reputation: 1819

Probably you should implement a method that listen to text change in UITextField. using

[textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];

So that you should be knowing whenever user enter a charachter in UITextFiled from that you can check if user has entered white space delete that and prompt user to write again.

Here is how you can delete last charecter that user have entered whenever textFieldDidChange: is called and you checked that user has entered white space

if ( [myString length] > 0)
{
     myString = [myString substringToIndex:[string length] - 1];
}

Upvotes: 1

Related Questions