2 // IASKSpecifierValuesViewController.m
3 // http://www.inappsettingskit.com
6 // Luc Vandal, Edovia Inc., http://www.edovia.com
7 // Ortwin Gentz, FutureTap GmbH, http://www.futuretap.com
8 // All rights reserved.
10 // It is appreciated but not required that you give credit to Luc Vandal and Ortwin Gentz,
11 // as the original authors of this code. You can give credit in a blog post, a tweet or on
12 // a info page of your app. Also, the original authors appreciate letting them know if you use this code.
14 // This code is licensed under the BSD license that is available at: http://www.opensource.org/licenses/bsd-license.php
17 #import "IASKSpecifierValuesViewController.h"
18 #import "IASKSpecifier.h"
19 #import "IASKSettingsReader.h"
21 #define kCellValue @"kCellValue"
23 @implementation IASKSpecifierValuesViewController
25 @synthesize currentSpecifier=_currentSpecifier;
26 @synthesize checkedItem=_checkedItem;
27 @synthesize settingsReader = _settingsReader;
30 // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
31 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
32 if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
33 // Custom initialization
40 /*- (void)viewDidLoad {
44 - (void)viewWillAppear:(BOOL)animated {
45 if (_currentSpecifier) {
46 [self setTitle:[_currentSpecifier title]];
50 [_tableView reloadData];
52 [super viewWillAppear:animated];
55 - (void)viewDidAppear:(BOOL)animated {
56 [_tableView flashScrollIndicators];
57 [super viewDidAppear:animated];
61 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
62 return (interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
65 - (void)didReceiveMemoryWarning {
66 // Releases the view if it doesn't have a superview.
67 [super didReceiveMemoryWarning];
69 // Release any cached data, images, etc that aren't in use.
72 - (void)viewDidUnload {
73 // Release any retained subviews of the main view.
74 // e.g. self.myOutlet = nil;
79 [_currentSpecifier release];
80 [_settingsReader release];
81 _settingsReader = nil;
88 #pragma mark UITableView delegates
90 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
94 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
95 return [_currentSpecifier multipleValuesCount];
98 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
99 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellValue];
100 NSArray *values = [_currentSpecifier multipleValues];
101 NSArray *titles = [_currentSpecifier multipleTitles];
104 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellValue] autorelease];
107 if ([[NSUserDefaults standardUserDefaults] objectForKey:[_currentSpecifier key]] ?
108 [[[NSUserDefaults standardUserDefaults] objectForKey:[_currentSpecifier key]] isEqual:[values objectAtIndex:indexPath.row]] :
109 [[_currentSpecifier defaultValue] isEqual:[values objectAtIndex:indexPath.row]]) {
110 [self setCheckedItem:indexPath];
111 [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
114 [cell setAccessoryType:UITableViewCellAccessoryNone];
118 [[cell textLabel] setText:[self.settingsReader titleForStringId:[titles objectAtIndex:indexPath.row]]];
120 @catch (NSException * e) {}
124 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
125 if (indexPath == [self checkedItem]) {
126 [tableView deselectRowAtIndexPath:indexPath animated:YES];
130 NSArray *values = [_currentSpecifier multipleValues];
132 [tableView deselectRowAtIndexPath:indexPath animated:YES];
133 [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
134 [[tableView cellForRowAtIndexPath:[self checkedItem]] setAccessoryType:UITableViewCellAccessoryNone];
135 [self setCheckedItem:indexPath];
137 [[NSUserDefaults standardUserDefaults] setObject:[values objectAtIndex:indexPath.row] forKey:[_currentSpecifier key]];
138 [[NSNotificationCenter defaultCenter] postNotificationName:kIASKAppSettingChanged object:[_currentSpecifier key]];