Sunday, June 8, 2014

iOS Tutorial - Part 11 - Converter App, IBOutlet, UITextField, UILabel, IBAction

Convert Miles to Feet App


Video Description 

IBOutlet

Identifier used to identify a property so Interface Builder can synchronize the display and connection of outlets with Xcode.
@property (weak, nonatomic) IBOutlet UILabel *resultLabel;

UITextField


is a control that displays editable text and sends an action message to a target object when the user presses the return button. You typically use this class to gather small amounts of text from the user and perform some immediate action, such as a search operation, based on that text. It has a method called "text" that returns the value that user typed.
@property (weak, nonatomic) IBOutlet UITextField *milesField;

NSString *numberThatUserTyped = self.milesField.text;

UILabel

Implements a read-only text view. You can use this class to draw one or multiple lines of static text, such as those you might use to identify other parts of your user interface. It has a method called "text" that we can set the value of the label.
@property (weak, nonatomic) IBOutlet UILabel *resultLabel;
self.resultLabel.text = @"The result";

IBAction

Use this type as the return type of any action methods defined in your project. It returns nothing (void), it just a way that Xcode understands it's target action connection.
- (IBAction)convertPressed {
    
}

Source code

//
//  ViewController.m
//  ReviewSession
//
//  Created by HuxTek on 5/25/14.
//  Copyright (c) 2014 HuxTek. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *milesField;
@property (weak, nonatomic) IBOutlet UILabel *resultLabel;
@end

@implementation ViewController

- (IBAction)convertPressed {
    float miles = [self.milesField.text floatValue];
    // 1 miles = 5280.0 feet
    float feet = miles * 5280.0;
    self.resultLabel.text = [[NSNumber numberWithFloat:feet] stringValue];
}

@end

Download

Download converter App from here

No comments:

Post a Comment