//
//  ViewController.m
//  HelloWorld
//
//  Created by twer on 4/19/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ViewController.h"

@implementation ViewController
@synthesize textField=_textField;
@synthesize displayField=_displayField;
@synthesize label=_label;
@synthesize userName=_userName;

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

- (void)viewDidUnload
{
    [self setTextField:nil];
    [self setDisplayField:nil];
    [self setLabel:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField{
    if (theTextField==self.textField)
    {
        [theTextField resignFirstResponder];
    }
         return YES;
}

- (IBAction)changeGreeting:(id)sender {
    self.userName=self.textField.text;
    NSString *nameString=self.userName;
    if ([nameString length]==0)
    {
        nameString=@"World";
    }
    NSString *greeting=[[NSString alloc] initWithFormat:@"Hello, %@!", nameString];
    
    self.label.text=greeting;
    self.label.accessibilityValue=greeting;
    
    self.displayField.text=greeting;
    self.displayField.accessibilityValue=greeting;
}

@end
