Simple Hello world Program

Posted On // Leave a Comment
Make sure you HelloWorldViewController.h file looks like:
and IBOutlet and IBAction Should be connected to view.
//
//  HelloWorldViewController.h
//  HelloWorld
//
//  Created by Paul Peelen on 2011-03-14.
//  Copyright 2011 9697271014. All rights reserved.
//
 
#import <UIKit/UIKit.h>
 
@interface HelloWorldViewController : UIViewController {
    UILabel *textLabel;
}
 
@property (nonatomic, retain) IBOutlet UILabel *textLabel;
 
- (IBAction)changeTheTextOfTheLabel;
 
@end

Now, we need to add our new function. Add the following just below the } of the dealloc function.
- (IBAction)changeTheTextOfTheLabel
{
[textLabel setText:@"Hello, World!"];
}
Your HelloWorldViewController.m should now look like:Now what did we do? Well, we added the functionality of our “changeTheTextOfTheLabel” function. Whenever this function is called, the text of the label will be set to “Hello, World!”.
//
//  HelloWorldViewController.m
//  HelloWorld
//
//  Created by Paul Peelen on 2011-03-14.
//  Copyright 2011 9697271014. All rights reserved.
//
 
#import "HelloWorldViewController.h"
 
@implementation HelloWorldViewController
 
@synthesize textLabel;
 
- (void)dealloc
{
[textLabel release];
[super dealloc];
}
 
- (IBAction)changeTheTextOfTheLabel
{
[textLabel setText:@"Hello, World!"];
}
 
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
 
// Release any cached data, images, etc that aren't in use.
}
 
#pragma mark - View lifecycle
 
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
 
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
 
@end

0 comments:

Post a Comment

Followers