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

issue with TPKeyboardAvoidingScrollView

Im trying to implement a way to limit the number of characters that can be typed into my username text field. Im currently doing it using this method:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSUInteger newLength = [textField.text length] + [string length] - range.length;

    if (newLength > 15) {

        return NO;

    } else {

        return YES;
    }
}

and setting the delegate in view did load of my login view controller

However, doing that (setting the delegate in my view controller) screws up tpkeyboardavoiding for that text view (it still avoids the keyboard, but certain things like the button changing to next doesnt work, it just stays as return and it doesnt advance down to the next field.

How can I manually change the button to next in code in my view controller , and how can I advance to the next field when the next button is pressed? Ive tried looking at the Tpkeyboardavoiding.m but the code is a bit above my level right now.

1 Answer

figured it out. I just set the return key as a next key for my username field in view did load using:

self.usernameField.returnKeyType = UIReturnKeyNext;

and implemented this method to advance to the password field

- (BOOL)textFieldShouldReturn:(UITextField *)textField {

    [self.passwordField becomeFirstResponder];
    return YES;

}

I guess since TPKeyboardAvoidingScrollView sets the textview delegates as the scroll view it screws up when you set the view controller as the delegate for one of them. Oh well. Easy fix