OK I am new to this. This is my first app so please be nice... I am working on an app to convert units. Yes I know they are out there but I want to learn. The problem I am running into is getting the view to redraw once I click out of the text box. I dont want to have to click a calculate button.
Code:
//
// ViewController.m
// MedConversion
//
// Created by Wayne Beck on 2/23/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (IBAction)reset {
1.text = @"0";
2.text = @"0";
3.text = @"0";
4.text = @"0";
5.text = @"0";
6.text = @"0";
7.text = @"0";
8.text = @"0";
9.text = @"0";
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if (touch.tapCount >= 1) {
[1 resignFirstResponder];
[2 resignFirstResponder];
[3 resignFirstResponder];
[4 resignFirstResponder];
[5 resignFirstResponder];
[6 resignFirstResponder];
[7 resignFirstResponder];
[8 resignFirstResponder];
[9 resignFirstResponder];
}
}
-(IBAction) resignResponder {
[1 resignFirstResponder];
[2 resignFirstResponder];
[3 resignFirstResponder];
[4 resignFirstResponder];
[5 resignFirstResponder];
[6 resignFirstResponder];
[7 resignFirstResponder];
[8 resignFirstResponder];
[9 resignFirstResponder];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == 1) {
[1 resignFirstResponder];
double c = (5.0/9.0)*([1.text doubleValue]-32.0);
double k = c - 273.15;
2.text = [[NSString alloc]initWithFormat:@"%2.1f", c];
3.text = [[NSString alloc]initWithFormat:@"%2.1f", k];
}
if (textField == 2) {
[2 resignFirstResponder];
double f = (9.0/5.0*[2.text doubleValue])+32.0;
double k = [2.text doubleValue] - 273.15;
1.text = [[NSString alloc]initWithFormat:@"%2.1f", f];
3.text = [[NSString alloc]initWithFormat:@"%2.1f", k];
}
if (textField == 3) {
[3 resignFirstResponder];
double c = [3.text doubleValue] + 273.15;
double f = (9.0/5.0*c)+32.0;
2.text = [[NSString alloc]initWithFormat:@"%2.1f", c];
1.text = [[NSString alloc]initWithFormat:@"%2.1f", f];
}
return YES;
}
/*- (void)drawRect:(CGRect)rect {
// Drawing code
}*/
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
Last edited by a moderator: