Advertisement
thieumao

Hide keyboard when click return

May 4th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "ViewController.h"
  2.  
  3. @interface ViewController ()
  4. - (IBAction)changeGreeting:(id)sender;
  5. @property (weak, nonatomic) IBOutlet UITextField *textFiled;
  6. @property (weak, nonatomic) IBOutlet UILabel *label;
  7.  
  8. @end
  9.  
  10. @implementation ViewController
  11.  
  12. - (void)viewDidLoad {
  13.     [super viewDidLoad];
  14.     // Do any additional setup after loading the view, typically from a nib.
  15. }
  16.  
  17. - (void)didReceiveMemoryWarning {
  18.     [super didReceiveMemoryWarning];
  19.     // Dispose of any resources that can be recreated.
  20. }
  21.  
  22. - (IBAction)changeGreeting:(id)sender {
  23.     self.userName = self.textFiled.text;
  24.     NSString *nameString = self.userName;
  25.     if ([nameString length] == 0)
  26.     {
  27.         nameString = @"World";
  28.     }
  29.     NSString *greeting = [[NSString alloc] initWithFormat:@"Hello, %@!", nameString];
  30.     self.label.text = greeting;
  31. }
  32.  
  33. - (BOOL) textFieldShouldReturn:(UITextField *)theTextField
  34. {
  35.     if (theTextField == self.textFiled)
  36.     {
  37.         [theTextField resignFirstResponder];
  38.     }
  39.     return YES;
  40. }
  41. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement