//
//  HelloUserViewController.m
//  HelloUser
//
//  Created by Chris Adamson on 1/1/09.
//  Copyright Subsequently and Furthermore, Inc. 2009. All rights reserved.
//
//
//  Licensed with the Apache 2.0 License
//  http://apache.org/licenses/LICENSE-2.0
//

#import "HelloUserViewController.h"

@implementation HelloUserViewController

//START:code.HelloUser.HelloUserViewController.propertysynthesize
@synthesize helloLabel, nameField;
//END:code.HelloUser.HelloUserViewController.propertysynthesize

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

/* verbose version
//START:code.HelloUser.HelloUserViewController.sayhellowithoutautorelease
- (void) sayHello: (id) sender {
	NSString *userName = nameField.text; //<label id="code.hellouserviewcontroller.sayhellowithoutautorelease.getnamefieldtext"/>
	NSString *helloMessage =  //<label id="code.hellouserviewcontroller.sayhellowithoutautorelease.createmessage"/>
		[[NSString alloc] initWithFormat: @"Hello %@", userName];
	helloLabel.text = helloMessage; //<label id="code.hellouserviewcontroller.sayhellowithoutautorelease.setlabeltext"/>
	[helloMessage release]; //<label id="code.hellouserviewcontroller.sayhellowithoutautorelease.releasemessage"/>
	nameField.text = @""; //<label id="code.hellouserviewcontroller.sayhellowithoutautorelease.cleartextfield"/>
}
//END:code.HelloUser.HelloUserViewController.sayhellowithoutautorelease
 */


/* concise autoreleasing version
 */
//START:code.HelloUser.HelloUserViewController.sayhellowithautoreleaseandproperties
- (void) sayHello: (id) sender {
	helloLabel.text =
		[NSString stringWithFormat: @"Hello %@", nameField.text];
	[nameField resignFirstResponder];
	nameField.text = @"";
}
//END:code.HelloUser.HelloUserViewController.sayhellowithautoreleaseandproperties

/* somewhat pathological non-properties version, used only to make a point in the book text
//START:code.HelloUser.HelloUserViewController.sayhellowithautoreleasebutnotproperties
- (void) sayHello: (id) sender {
	[helloLabel setText:
		[NSString stringWithFormat: @"Hello %@", [nameField text]]];
	[nameField resignFirstResponder];
	nameField.text = @"";
}
//END:code.HelloUser.HelloUserViewController.sayhellowithautoreleasebutnotproperties
 */

//START:code.HelloUser.HelloUserViewController.textfieldshouldreturn
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	[textField resignFirstResponder];
	return YES;
}
//END:code.HelloUser.HelloUserViewController.textfieldshouldreturn

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


//START:code.HelloUser.HelloUserViewController.dealloc
- (void)dealloc {
	[helloLabel release];
	[nameField release];
	[super dealloc];
}
//END:code.HelloUser.HelloUserViewController.dealloc

@end
