Reputation: 1278
How can I append a string by adding '.' onto a UITextField? I have tried this: [textfield.text stringByAppendingString:@"."];
but I am getting strange behavior - it converts the last character into a .
instead of adding on. (I also use this code to add 0-9 chars and it works perfectly.)
Any other methods of appending the .
and/or an explanations for this?
Upvotes: 1
Views: 6530
Reputation: 37
Swift
CommentTextField.text = CommentTextField.text?.stringByAppendingString(string)
Upvotes: 1
Reputation: 92414
You need to do textfield.text = [textfield.text stringByAppendingString:@"."];
since the stringByAppendingString:
returns a new string, it doesn't modify the existing one (as strings are immutable by default).
Upvotes: 8
Reputation: 47241
Try this:
textfield.text = [NSString stringWithFormat:@"%@.", textfield.text];
Upvotes: 2