Skip to content

Commit

Permalink
Update to display current selected option
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasuhiro Asaka committed Aug 7, 2013
1 parent e9c1835 commit e2673a5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 17 deletions.
2 changes: 1 addition & 1 deletion generika.xcodeproj/project.pbxproj
Expand Up @@ -355,9 +355,9 @@
81B8621E153704330054EA0A /* WebViewController.h */,
81B8621F153704330054EA0A /* WebViewController.m */,
812B9A4B17AF7DF50001A5A8 /* SettingsViewController.h */,
812B9A4C17AF7DF50001A5A8 /* SettingsViewController.m */,
8148C65917B0B9530037EE81 /* SettingsDetailViewController.h */,
8148C65A17B0B9530037EE81 /* SettingsDetailViewController.m */,
812B9A4C17AF7DF50001A5A8 /* SettingsViewController.m */,
8129BA54153D46F100CB5896 /* Reachability.h */,
8129BA55153D46F100CB5896 /* Reachability.m */,
81FEDA1F1538962900756CAE /* Resources */,
Expand Down
6 changes: 3 additions & 3 deletions generika/MasterViewController.m
Expand Up @@ -295,9 +295,9 @@ - (void)didFinishPicking:(id)json withEan:(NSString *)ean barcode:(UIImage *)bar
publicPrice = [NSString stringWithFormat:@"CHF: %@", price];
}
NSString *message = [NSString stringWithFormat:@"%@,\n%@\n%@",
[product objectForKey:@"name"],
[product objectForKey:@"size"],
publicPrice];
[product objectForKey:@"name"],
[product objectForKey:@"size"],
publicPrice];
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Generika.cc sagt:"
message:message
delegate:self
Expand Down
7 changes: 4 additions & 3 deletions generika/SettingsDetailViewController.m
Expand Up @@ -89,8 +89,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.accessoryType = UITableViewCellAccessoryNone;
}
// name
_nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 8.0, 100.0, 25.0)];
_nameLabel.font = [UIFont boldSystemFontOfSize:14.0];
_nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 8.0, 120.0, 25.0)];
_nameLabel.font = [UIFont boldSystemFontOfSize:16.0];
_nameLabel.textAlignment = UITextAlignmentLeft;
_nameLabel.textColor = [UIColor blackColor];
_nameLabel.backgroundColor = [UIColor clearColor];
Expand All @@ -106,9 +106,10 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
//DLog(@"indexPath.row = %i", indexPath.row);
//DLog(@"_selectedPath.row = %i", _selectedPath.row);
if (indexPath.row != _selectedPath.row) {
// uncheck
UITableViewCell *prev = [tableView cellForRowAtIndexPath:_selectedPath];
prev.accessoryType = UITableViewCellAccessoryNone;

// check & store
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[_userDefaults setInteger:indexPath.row forKey:_defaultKey];
Expand Down
7 changes: 7 additions & 0 deletions generika/SettingsViewController.h
Expand Up @@ -13,10 +13,17 @@
@interface SettingsViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
SettingsDetailViewController *_settingsDetail;

NSArray *_settings;
NSArray *_types;
NSArray *_languages;

NSUserDefaults *_userDefaults;

UITableView *_settingsView;
UILabel *_sectionLabel;
UILabel *_nameLabel;
UILabel *_optionLabel;
}

@end
52 changes: 42 additions & 10 deletions generika/SettingsViewController.m
Expand Up @@ -21,9 +21,16 @@ - (id)init
{
self = [super initWithNibName:nil
bundle:nil];
_userDefaults = [NSUserDefaults standardUserDefaults];
return self;
}

- (void)viewWillAppear:(BOOL)animated
{
[_settingsView reloadData];
[super viewWillAppear:animated];
}

- (void)viewDidLoad
{
[super viewDidLoad];
Expand All @@ -35,7 +42,10 @@ - (void)viewDidLoad
target:self
action:@selector(closeSettings)];
self.navigationItem.leftBarButtonItem = closeButton;
// contents
_settings = [NSArray arrayWithObjects:@"Search", @"Language", nil];
_types = [NSArray arrayWithObjects:@"Preisvergleich", @"PI", @"FI", nil];
_languages = [NSArray arrayWithObjects:@"Deutsch", @"Français", nil];
// table view
CGRect screenBounds = [[UIScreen mainScreen] bounds];
_settingsView = [[UITableView alloc] initWithFrame:screenBounds style:UITableViewStyleGrouped];
Expand Down Expand Up @@ -122,42 +132,64 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

// name
_nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 8.0, 100.0, 25.0)];
_nameLabel.font = [UIFont boldSystemFontOfSize:14.0];
_nameLabel.font = [UIFont boldSystemFontOfSize:16.0];
_nameLabel.textAlignment = UITextAlignmentLeft;
_nameLabel.textColor = [UIColor blackColor];
_nameLabel.backgroundColor = [UIColor clearColor];
_nameLabel.text = [_settings objectAtIndex:indexPath.row];
// option
_optionLabel = [[UILabel alloc] initWithFrame:CGRectMake(160.0, 8.0, 110.0, 25.0)];
_optionLabel.font = [UIFont systemFontOfSize:16.0];
_optionLabel.textAlignment = UITextAlignmentRight;
_optionLabel.textColor = [UIColor colorWithRed:0.2 green:0.33 blue:0.5 alpha:1.0];
_optionLabel.backgroundColor = [UIColor clearColor];

NSDictionary *context = [self contextFor:indexPath];
NSInteger selectedRow = [_userDefaults integerForKey:[context objectForKey:@"key"]];
//DLog(@"selectedRow = %i", selectedRow);
//DLog(@"options = %@", [context objectForKey:@"options"]);
_optionLabel.text = [[context objectForKey:@"options"] objectAtIndex:selectedRow];
[cell.contentView addSubview:_nameLabel];
[cell.contentView addSubview:_optionLabel];
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];

// next
_settingsDetail = [[SettingsDetailViewController alloc] init];
_settingsDetail.title = [_settings objectAtIndex:indexPath.row];
//DLog(@"indexPath.row = %i", indexPath.row);
NSDictionary *context = [self contextFor:indexPath];
_settingsDetail.options = [context objectForKey:@"options"];
_settingsDetail.defaultKey = [context objectForKey:@"key"];
[self.navigationController pushViewController:_settingsDetail animated:YES];
}

- (NSDictionary *)contextFor:(NSIndexPath *)indexPath
{
//DLog(@"indexPath.row = %i", indexPath.row)
switch (indexPath.row) {
case 0:
_settingsDetail.options = [NSArray arrayWithObjects:@"Preisvergleich", @"PI", @"FI", nil];
_settingsDetail.defaultKey = @"search.result.type";
return [NSDictionary dictionaryWithObjectsAndKeys:
_types, @"options",
@"search.result.type", @"key",
nil];
break;
case 1:
_settingsDetail.options = [NSArray arrayWithObjects:@"Deutsch", @"Français", nil];
_settingsDetail.defaultKey = @"search.result.lang";
return [NSDictionary dictionaryWithObjectsAndKeys:
_languages, @"options",
@"search.result.lang", @"key",
nil];
break;
default:
// unexpected
_settingsDetail.options = [NSArray arrayWithObjects:nil];
_settingsDetail.defaultKey = @"";
return [NSDictionary dictionaryWithObjectsAndKeys:nil];
break;
}
[self.navigationController pushViewController:_settingsDetail animated:YES];
}

@end

0 comments on commit e2673a5

Please sign in to comment.