home

Friday, March 16, 2012

temp converter part two

8. After ViewController.h done then click on ViewController.m, you could find the code at ViewController.m like the code below:




//
//  ViewController.m
//  converter
//
//  Created by.... on....
//  Copyright (c) 2012 your company. All rights reserved.
//

#import "ViewController.h"

@implementation ViewController
@synthesize fahrenheit;
@synthesize celsius;

*Note = these codes below came from IBOutlet on ViewController.h that we made it before.

@synthesize fahrenheit;
@synthesize celsius;

next step is =

insert the following code just below the code

-(void)viewDidLoad
{
    [super viewDidLoad]; 

the code is =

fahrenheit.keyboardType = UIKeyboardTypeDecimalPad;


9.  Change the code below =

- (IBAction)convert:(id)sender {
}

copy and paste with the code below =

 - (IBAction)convert:(id)sender {
    float x = [[fahrenheit text] floatValue];
    float y = (x - 32.0f) * 5.0f / 9.0f;
    [celsius setText : [NSString stringWithFormat:@"%.3.2f", y]];
    [fahrenheit resignFirstResponder];
}




then run the application, have a nice try 








/>

No comments:

Post a Comment