
#import "FirstViewController.h"
#import "TwoXibsAppDelegate.h"


@implementation FirstViewController

@synthesize helloWorld;

- (void)updateDisplay {
	//funcation is called when NSNotificationCenter receives @"BlueIsSet" message.
	//setting the color and calling setNeedsDisplay should update the color without having to press the say hi button
	NSLog(@"updateDisplay in firstView");
	TwoXibsAppDelegate *md = (TwoXibsAppDelegate *)[[UIApplication sharedApplication] delegate];
	helloWorld.textColor = md.helloWorldColor;
	[helloWorld setNeedsDisplay];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
	if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
		// Initialization code
		//register with the Notification Center to automatically call updateDisplay() when a "BlueIsSet" notification is received
		NSNotificationCenter *dc = [NSNotificationCenter defaultCenter];
		[dc addObserver:self selector:@selector(updateDisplay) name:@"BlueIsSet" object:nil];
		}
	return self;
}

- (IBAction)sayHi:(id)sender {
	[[self helloWorld] setText:@"Hello, World!"];
	TwoXibsAppDelegate *md = (TwoXibsAppDelegate *)[[UIApplication sharedApplication] delegate];
	helloWorld.textColor = md.helloWorldColor;
}

- (IBAction)gotoSettings:(id)sender {
	TwoXibsAppDelegate *md = (TwoXibsAppDelegate *)[[UIApplication sharedApplication] delegate];
	[md flipViews:self];
}

/*
 Implement loadView if you want to create a view hierarchy programmatically
- (void)loadView {
}
 */

/*
 If you need to do additional setup after loading the view, override viewDidLoad.
- (void)viewDidLoad {
}
 */


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


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


- (void)dealloc {
	[helloWorld release];
	[super dealloc];
}


@end
