Last active
January 2, 2016 22:09
-
-
Save neojou/8367832 to your computer and use it in GitHub Desktop.
iphone hello world
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface HelloWorldViewController : UIViewController <UITextFieldDelegate> | |
@property (copy, nonatomic) NSString *userName; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "HelloWorldViewController.h" | |
@interface HelloWorldViewController () | |
@property (weak, nonatomic) IBOutlet UITextField *textField; | |
- (IBAction)changeGreeting:(id)sender; | |
@property (weak, nonatomic) IBOutlet UIButton *label; | |
@end | |
@implementation HelloWorldViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
- (IBAction)changeGreeting:(id)sender { | |
self.userName = self.textField.text; | |
NSString *nameString = self.userName; | |
if ([nameString length] == 0) { | |
nameString = @"World"; | |
} | |
NSString *greeting = [[NSString alloc] initWithFormat:@"Hello, %@!", nameString]; | |
[self.label setTitle:greeting forState:UIControlStateNormal]; | |
} | |
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField { | |
if (theTextField == self.textField) { | |
[theTextField resignFirstResponder]; | |
} | |
return YES; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment