cocoaTouch/SettingsViewController.m
changeset 2694 dcd248e04f3d
parent 2687 28b8330b8af1
child 2696 41aa7b56c17b
equal deleted inserted replaced
2693:3207e0eacd43 2694:dcd248e04f3d
     9 #import "SettingsViewController.h"
     9 #import "SettingsViewController.h"
    10 
    10 
    11 
    11 
    12 @implementation SettingsViewController
    12 @implementation SettingsViewController
    13 
    13 
    14 /*
    14 @synthesize username, password, musicOn, effectsOn, volumeSlider, volumeLabel;
    15  // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    15 
    16 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    16 -(NSString *)dataFilePath: (NSString *)fileName {
    17     if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    17 	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    18         // Custom initialization
    18 	NSString *documentsDirectory = [paths objectAtIndex:0];
    19     }
    19 	return [documentsDirectory stringByAppendingPathComponent:fileName];
    20     return self;
       
    21 }
    20 }
    22 */
       
    23 
    21 
    24 /*
    22 
    25 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    23 -(void) viewDidLoad {
    26 - (void)viewDidLoad {
    24 	NSString *filePath = [self dataFilePath:@"settings.plist"];
    27     [super viewDidLoad];
    25 	
       
    26 	if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {	
       
    27 		NSUserDefaults *data = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
       
    28 		username.text = [data objectForKey:@"username"];
       
    29 		password.text = [data objectForKey:@"password"];
       
    30 		if (1 == [[data objectForKey:@"music"] intValue]) {
       
    31 			musicOn.on = YES;
       
    32 		} else {
       
    33 			musicOn.on = NO;
       
    34 		}
       
    35 		if (1 == [[data objectForKey:@"effects"] intValue]) {
       
    36 			effectsOn.on = YES;
       
    37 		} else {
       
    38 			effectsOn.on = NO;
       
    39 		}
       
    40 		[volumeSlider setValue:[[data objectForKey:@"volume"] intValue] animated:NO];
       
    41 		NSString *tmpVol = [[NSString alloc] initWithFormat:@"%d", (int) volumeSlider.value];
       
    42 		volumeLabel.text = tmpVol;
       
    43 		[tmpVol release];
       
    44 	}
       
    45 	
       
    46 	
       
    47 /*	
       
    48 	UIApplication *app = [UIApplication sharedApplication];
       
    49 	[[NSNotificationCenter defaultCenter] addObserver:self
       
    50 											 selector:@selector(applicationWillTerminate:)
       
    51 												 name:UIApplicationWillTerminateNotification
       
    52 											   object:app];
       
    53 */	[super viewDidLoad];
    28 }
    54 }
    29 */
       
    30 
    55 
       
    56 -(void) viewDidUnload {
       
    57 	self.username = nil;
       
    58 	self.password = nil;
       
    59 	self.musicOn = nil;
       
    60 	self.effectsOn = nil;
       
    61 	self.volumeLabel = nil;
       
    62 	self.volumeSlider = nil;
       
    63 	[super viewDidUnload];
       
    64 }
       
    65 
       
    66 //- (void)applicationWillTerminate:(NSNotification *)notification {
       
    67 -(void) viewWillDisappear:(BOOL)animated {
       
    68 	NSMutableDictionary *saveArray = [[NSMutableDictionary alloc] init];
       
    69 	NSString *tmpMus = (musicOn.on) ? @"1" : @"0";
       
    70 	NSString *tmpEff = (effectsOn.on) ? @"1" : @"0";
       
    71 	
       
    72 	[saveArray setObject:username.text forKey:@"username"];
       
    73 	[saveArray setObject:password.text forKey:@"password"];
       
    74 	[saveArray setObject:tmpMus forKey:@"music"];
       
    75 	[saveArray setObject:tmpEff forKey:@"effects"];
       
    76 	[saveArray setObject:volumeLabel.text forKey:@"volume"];
       
    77 	
       
    78 	[saveArray writeToFile:[self dataFilePath:@"settings.plist"] atomically:YES];
       
    79 	[saveArray release];
       
    80 	[super viewWillDisappear:animated];
       
    81 }
       
    82  
    31 /*
    83 /*
    32 // Override to allow orientations other than the default portrait orientation.
    84 // Override to allow orientations other than the default portrait orientation.
    33 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    85 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    34     // Return YES for supported orientations
    86     // Return YES for supported orientations
    35     return (interfaceOrientation == UIInterfaceOrientationPortrait);
    87     return (interfaceOrientation == UIInterfaceOrientationPortrait);
    36 }
    88 }
    37 */
    89 */
    38 
    90 
    39 - (void)didReceiveMemoryWarning {
    91 -(IBAction) backgroundTap: (id)sender {
    40 	// Releases the view if it doesn't have a superview.
    92 	[username resignFirstResponder];
    41     [super didReceiveMemoryWarning];
    93 	[password resignFirstResponder];
    42 	
       
    43 	// Release any cached data, images, etc that aren't in use.
       
    44 }
    94 }
    45 
    95 
    46 - (void)viewDidUnload {
    96 -(IBAction) textFieldDoneEditing: (id)sender {
    47 	// Release any retained subviews of the main view.
    97 	[sender resignFirstResponder];
    48 	// e.g. self.myOutlet = nil;
       
    49 }
    98 }
    50 
    99 
       
   100 -(IBAction) sliderChanged: (id) sender {
       
   101 	UISlider *slider = (UISlider *)sender;
       
   102 	int progress = slider.value;
       
   103 	NSString *newLabel = [[NSString alloc] initWithFormat:@"%d",progress];
       
   104 	self.volumeLabel.text = newLabel;
       
   105 	[newLabel release];
       
   106 }
    51 
   107 
    52 - (void)dealloc {
   108 -(void) dealloc {
       
   109 	[username release];
       
   110 	[password release];
       
   111 	[musicOn release];
       
   112 	[effectsOn release];
       
   113 	[volumeLabel release];
       
   114 	[volumeSlider release];
    53     [super dealloc];
   115     [super dealloc];
    54 }
   116 }
    55 
   117 
    56 
   118 
    57 @end
   119 @end