13
- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{
    [self checkRun:nil];
    return YES;
}

I'm trying to complete the IBAction checkRun when the return key is pressed, by using the above code, but it doesn't seem to be working. Where am I going wrong? I thought maybe it's because I'm not directly referencing the textfield that I'm typing in, but I can't work out where I'd need to put the name of that textfield.

Thanks in advance.

lootsch
  • 1,867
  • 13
  • 21
Nathan
  • 155
  • 1
  • 2
  • 5

2 Answers2

15

ViewController.h:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITextFieldDelegate>

@end

ViewController.m:

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) UITextField *textField;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.textField.delegate = self;
}
klcjr89
  • 5,862
  • 10
  • 58
  • 91
  • 2
    This is right, thanks, but for reference, I got away with just dragging 'delegate' to the view controller in IB. Probably not good practice, but it worked. – Nathan Mar 16 '14 at 23:00
  • 4
    Actually, dragging the delegate to the view controller in IB is the best practice. – Uzaak Jan 30 '15 at 17:32
0

This UITextfield subclass enables you to set a condition for the text and dynamically change the UIReturnKey: https://github.com/codeinteractiveapps/OBReturnKeyTextField