title: UITextField with numbers only & "done" on keyboard on the iPhone
body: <p>I'm learning obj-c and gave myself a simple task of creation an app that has 2 <code>uitextfields</code>, <code>label</code> &amp; <code>button</code> (button summarizes 2 numbers and shows the result in label). I made this app but I haven't figured out how to make <code>textfields</code> interact with "done" button &amp; "numbers only" together.</p>
  
  <p>Below is my code:</p>
  
  <pre><code>#import UIKit/UIKit.h
  
  @interface ViewController : UIViewController
  
  @property IBOutlet UILabel *label;
  @property IBOutlet UITextField *textField1;
  @property IBOutlet UITextField *textField2;
  @property NSInteger textFieldInt1, textFieldInt2;
  @property NSString *textFieldStr1, *textFieldStr2;
  
  -(IBAction)button:(id)sender;
  -(IBAction)hideKeyboard:(id)sender;
  
  @end
  
  
  #import "ViewController.h"
  
  @interface ViewController ()
  @end
  
  @implementation ViewController
  
  @synthesize label, textField1, textField2, textFieldInt1, textFieldInt2, textFieldStr1, textFieldStr2;
  
  -(IBAction)button:(id)sender {
      textFieldInt1=[textField1.text integerValue];
      textFieldInt2=[textField2.text integerValue];
      label.text=[NSString stringWithFormat: @"%d", textFieldInt1+textFieldInt2];
      [self.view endEditing:YES];
  }
  
  
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  // Do any additional setup after loading the view, typically from a nib.
  
      [self.textField1 setReturnKeyType:UIReturnKeyDone];
      [self.textField2 setReturnKeyType:UIReturnKeyDone];
  
  }
  
  -(IBAction)hideKeyboard:(id)sender
  {
      [self.view endEditing:YES];
  }
  
  -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range     replacementString:(NSString *)string {
      if(![string intValue] &amp;&amp; ![string isEqualToString:@""] &amp;&amp; ![string isEqualToString:@"0"])
      {
      return NO;
      } else {
      return YES;
      }
  }
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
  }
  
  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
      [self.view endEditing:YES];
      [super touchesBegan:touches withEvent:event];
  }
  
  
  @end
  </code></pre>
  
  <p>Also I connected (in storyboard) both <code>textFields</code> to <code>hideKeyboard (didEndOnExit)</code>, and <code>button</code> to <code>button (touchUpInside)</code> and all outlets (<code>textfields</code>, <code>button</code>, <code>label</code>).</p>
  
  <p><strong>The problem is:</strong> <code>numbers only</code> input doesn't work with <code>done</code>. If I use <code>delegate</code> (new referencing outlet in storyboard connected to both <code>textfields</code>) I get <code>numbers only</code> input in <code>textfields</code> but the <code>done</code> button doesn't work (when I press it on the iPhone nothing happens). If I don't use <code>delegate</code> I get <code>all characters</code> input but <code>done</code> works fine (when I press it iPhone keyboard hides).</p>
  
  <p>Any suggestions what I may be doing wrong here?</p>