Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

martin chibwe
martin chibwe
3,901 Points

limit the char or sting in UIText filed

  • (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

NSUInteger maxLength = 40; NSUInteger textLength = [self.textField.text length] + [string length] - range.length;

if(textLength > maxLength) { return NO; } else { self.textField.text = [NSString stringWithFormat:@"%lu/%lu",(unsigned long)textLength,(unsigned long)maxLength]; return YES; } }

nothing is happing help

1 Answer

Please check my response to your other post.