Skip to content

Instantly share code, notes, and snippets.

@alvaro893
Last active May 14, 2016 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvaro893/cb9db863c959ec6d47f404279b23852f to your computer and use it in GitHub Desktop.
Save alvaro893/cb9db863c959ec6d47f404279b23852f to your computer and use it in GitHub Desktop.
objetive-c example for apple app
#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