Created
May 18, 2012 16:13
-
-
Save ninthspace/2726134 to your computer and use it in GitHub Desktop.
SettingsViewController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface SettingsViewController : UITableViewController | |
typedef enum { | |
AlistoPrefKeyTypeShowTaskNumbers = 0, | |
AlistoPrefKeyConfirmDeletion = 1 | |
} AlistoPrefKeyType; | |
@property (nonatomic, retain) IBOutlet UITableViewCell *showTaskNumbersCell; | |
@property (weak, nonatomic) IBOutlet UISwitch *showTaskNumbersSwitch; | |
- (IBAction)toggleShowTaskNumbersSwitch:(id)sender; | |
@property (nonatomic, retain) IBOutlet UITableViewCell *showTaskDeletionCell; | |
@property (weak, nonatomic) IBOutlet UISwitch *confirmTaskDeletionSwitch; | |
- (IBAction)toggleConfirmTaskDeletionSwitch:(id)sender; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "SettingsViewController.h" | |
@interface SettingsViewController () | |
@end | |
@implementation SettingsViewController | |
@synthesize showTaskNumbersCell; | |
@synthesize showTaskNumbersSwitch; | |
@synthesize showTaskDeletionCell; | |
@synthesize confirmTaskDeletionSwitch; | |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { | |
self = [super initWithNibName:@"SettingsViewController" bundle:nibBundleOrNil]; | |
if (self) { | |
// so that users cannot select any rows | |
[[self tableView] setAllowsSelection:NO]; | |
} | |
return self; | |
} | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
[[self navigationItem] setTitle:@"Settings"]; | |
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButton:)]; | |
[[self navigationItem] setRightBarButtonItem:doneButton]; | |
// display settings | |
[showTaskNumbersSwitch setOn:[[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"%d", AlistoPrefKeyTypeShowTaskNumbers]]]; | |
[confirmTaskDeletionSwitch setOn:[[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"%d", AlistoPrefKeyConfirmDeletion]]]; | |
} | |
- (void)viewDidDisappear:(BOOL)animated { | |
[super viewDidDisappear:animated]; | |
} | |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView | |
{ | |
return 1; | |
} | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section | |
{ | |
return 2; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
switch ([indexPath row]) { | |
case 0: return [self showTaskNumbersCell]; | |
case 1: return [self showTaskDeletionCell]; | |
default: ; | |
} | |
} | |
- (IBAction)doneButton:(id)sender { | |
[self removeView]; | |
} | |
- (void)removeView { | |
[[self presentingViewController] dismissModalViewControllerAnimated:YES]; | |
} | |
- (IBAction)toggleShowTaskNumbersSwitch:(id)sender { | |
[[NSUserDefaults standardUserDefaults] setBool:[sender isOn] forKey:[NSString stringWithFormat:@"%d", AlistoPrefKeyTypeShowTaskNumbers]]; | |
} | |
- (IBAction)toggleConfirmTaskDeletionSwitch:(id)sender { | |
[[NSUserDefaults standardUserDefaults] setBool:[sender isOn] forKey:[NSString stringWithFormat:@"%d", AlistoPrefKeyConfirmDeletion]]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment