2

I have used all the suggestions on the forum and still can not go from one uitextfield to the other by hitting the next button. Am i missing something or have something out of place. Any help would be great. Thanks.

Here is all of my code:

//.h file
#import <UIKit/UIKit.h>

@interface IncomeTransactionViewController : UIViewController  


@property (strong, nonatomic) IBOutlet UITextField *businessField;
@property (strong, nonatomic) IBOutlet UITextField *memoField;
@property (strong, nonatomic) IBOutlet UITextField *amountField;


@end

//.m file
#import "IncomeTransactionViewController.h"

@interface IncomeTransactionViewController ()

@end

@implementation IncomeTransactionViewController


- (void)viewDidLoad
{
    [super viewDidLoad];

     //Business UITextField
    self.businessField = [[UITextField alloc] initWithFrame:CGRectMake(20, 300, 280, 40)];

    self.businessField.returnKeyType = UIReturnKeyNext;
    self.businessField.placeholder = @"Business";
    self.businessField.autocapitalizationType = UITextAutocapitalizationTypeWords;
    self.businessField.adjustsFontSizeToFitWidth = TRUE;
    self.businessField.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:self.businessField];

    //Memo UITextField
    self.memoField = [[UITextField alloc] initWithFrame:CGRectMake(20, 350, 280, 40)];

    self.memoField.returnKeyType = UIReturnKeyNext;
    self.memoField.placeholder = @"Memo";
    self.memoField.autocapitalizationType = UITextAutocapitalizationTypeWords;
    self.memoField.adjustsFontSizeToFitWidth = TRUE;
    self.memoField.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:self.memoField];

    //Amount UITextField
    self.amountField = [[UITextField alloc] initWithFrame:CGRectMake(20, 400, 280, 40)];

    self.amountField.returnKeyType = UIReturnKeyDone;
    self.amountField.placeholder = @"Amount";
    self.amountField.autocapitalizationType = UITextAutocapitalizationTypeWords;
    self.amountField.adjustsFontSizeToFitWidth = TRUE;
    self.amountField.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:self.amountField];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (textField == self.amountField) {
        [textField resignFirstResponder];

    } else if (textField == self.businessField) {
        [self.businessField resignFirstResponder];
        [self.memoField becomeFirstResponder];

    } else if (textField == self.memoField) {
        [self.memoField resignFirstResponder];
        [self.amountField becomeFirstResponder];
    }
    return YES;
}

@end
  • I don't think you need the resignFirstResponder calls in the business and memo if blocks. Also, have you tried returning NO? – Joshua Sullivan Sep 26 '14 at 03:41
  • possible duplicate of [UITextField - Next Button](http://stackoverflow.com/questions/26050306/uitextfield-next-button) – Popeye Jun 17 '15 at 08:47

1 Answers1

0

You have to take the <UITextFieldDelegate> in your .h file

@interface IncomeTransactionViewController : UIViewController  <UITextFieldDelegate>

and in your .m file you need to assign delegate like this

self.businessField = [[UITextField alloc] initWithFrame:CGRectMake(20, 300, 280, 40)];
self.businessField.delegate = self; // add this line
self.businessField.returnKeyType = UIReturnKeyNext;
self.businessField.placeholder = @"Business";
self.businessField.autocapitalizationType = UITextAutocapitalizationTypeWords;
self.businessField.adjustsFontSizeToFitWidth = TRUE;
self.businessField.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:self.businessField];

//Memo UITextField
self.memoField = [[UITextField alloc] initWithFrame:CGRectMake(20, 350, 280, 40)];
self.memoField.delegate = self; // add this line
self.memoField.returnKeyType = UIReturnKeyNext;
self.memoField.placeholder = @"Memo";
self.memoField.autocapitalizationType = UITextAutocapitalizationTypeWords;
self.memoField.adjustsFontSizeToFitWidth = TRUE;
self.memoField.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:self.memoField];

//Amount UITextField
self.amountField = [[UITextField alloc] initWithFrame:CGRectMake(20, 400, 280, 40)];
self.amountField.delegate = self; // add this line
self.amountField.returnKeyType = UIReturnKeyDone;
self.amountField.placeholder = @"Amount";
self.amountField.autocapitalizationType = UITextAutocapitalizationTypeWords;
self.amountField.adjustsFontSizeToFitWidth = TRUE;
self.amountField.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:self.amountField];

This should do it. let me know if it still doesn't work

Ahmed Z.
  • 2,329
  • 23
  • 52