Last active
May 14, 2016 09:42
-
-
Save alvaro893/cb9db863c959ec6d47f404279b23852f to your computer and use it in GitHub Desktop.
objetive-c example for apple app
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 ViewController : UIViewController | |
@property (weak, nonatomic) IBOutlet UITextField *waterTextField; | |
@property (weak, nonatomic) IBOutlet UITextField *ratioTextField; | |
@property (weak, nonatomic) IBOutlet UITextField *coffeeTextField; | |
- (IBAction)calculateButtonPressed:(id)sender; | |
@end | |
// viewController.m | |
#import "ViewController.h" | |
@implementation ViewController | |
@synthesize waterTextField; | |
@synthesize ratioTextField; | |
@synthesize coffeeTextField; | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Release any cached data, images, etc that aren't in use. | |
} | |
#pragma mark - View lifecycle | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
- (void)viewDidUnload | |
{ | |
[self setWaterTextField:nil]; | |
[self setRatioTextField:nil]; | |
[self setCoffeeTextField:nil]; | |
[super viewDidUnload]; | |
// Release any retained subviews of the main view. | |
// e.g. self.myOutlet = nil; | |
} | |
- (void)viewWillAppear:(BOOL)animated | |
{ | |
[super viewWillAppear:animated]; | |
} | |
- (void)viewDidAppear:(BOOL)animated | |
{ | |
[super viewDidAppear:animated]; | |
} | |
- (void)viewWillDisappear:(BOOL)animated | |
{ | |
[super viewWillDisappear:animated]; | |
} | |
- (void)viewDidDisappear:(BOOL)animated | |
{ | |
[super viewDidDisappear:animated]; | |
} | |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation | |
{ | |
// Return YES for supported orientations | |
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { | |
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); | |
} else { | |
return YES; | |
} | |
} | |
- (IBAction)calculateButtonPressed:(id)sender { | |
NSLog(@"Calculate Pressed"); | |
float water = [[self.waterTextField text] floatValue]; | |
float ration = [[self.ratioTextField text] floatValue]; | |
NSLog(@"water: %f ration: %f", water, ration); | |
float coffee = water/ration; | |
NSString *coffeeText = [NSString stringWithFormat:@"%f", coffee]; | |
coffeeTextField.text = coffeeText; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment