//
//  StudentDetailViewController.m
//  StudentManager
//
//  Created by Rich on 2/9/11.
//  Copyright 2011 Swarthmore College. All rights reserved.
//

#import "StudentDetailViewController.h"


@implementation StudentDetailViewController
@synthesize nameField, gradyearField, majorField;
@synthesize editStudent;

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/

- (void)viewWillAppear:(BOOL)animated
{
	[super viewWillAppear:animated];
	
	self.nameField.text = editStudent.studentName;
	self.majorField.text = editStudent.deptMajor;
	self.gradyearField.text = [NSString stringWithFormat:@"%d", editStudent.gradyear];
	
	self.title = editStudent.studentName;
}


- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
	
	[nameField resignFirstResponder];
	[majorField resignFirstResponder];
	[gradyearField resignFirstResponder];
	
	self.editStudent.studentName = nameField.text;
	self.editStudent.deptMajor = majorField.text;
	self.editStudent.gradyear = [gradyearField.text intValue];
}

/*
// 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);
}
*/

- (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.
}

- (void)releaseOutlets
{
	self.nameField = nil;
	self.gradyearField = nil;
	self.majorField = nil;

}

- (void)viewDidUnload {
    [super viewDidUnload];
	[self releaseOutlets];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[self releaseOutlets];
    [super dealloc];
}


@end
