diff --git a/OptionSelector.xcodeproj/project.pbxproj b/OptionSelector.xcodeproj/project.pbxproj index 1788504..219bc7c 100644 --- a/OptionSelector.xcodeproj/project.pbxproj +++ b/OptionSelector.xcodeproj/project.pbxproj @@ -7,9 +7,12 @@ objects = { /* Begin PBXBuildFile section */ + 6B01EF871B7D1B34004151ED /* CQShadesData.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B01EF861B7D1B34004151ED /* CQShadesData.m */; }; + 6B9A63F41B7A9D4E0025CD30 /* CategoriesRootViewTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B9A63F31B7A9D4E0025CD30 /* CategoriesRootViewTableViewController.m */; }; + 6B9A63F71B7A9DA20025CD30 /* ListTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B9A63F61B7A9DA20025CD30 /* ListTableViewController.m */; }; + 6BB571A31B7ADDBB0065EE52 /* CQCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BB571A21B7ADDBB0065EE52 /* CQCategory.m */; }; 8DECE7921B78082B0064D760 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DECE7911B78082B0064D760 /* main.m */; }; 8DECE7951B78082B0064D760 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DECE7941B78082B0064D760 /* AppDelegate.m */; }; - 8DECE7981B78082B0064D760 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DECE7971B78082B0064D760 /* ViewController.m */; }; 8DECE79B1B78082B0064D760 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8DECE7991B78082B0064D760 /* Main.storyboard */; }; 8DECE79D1B78082B0064D760 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8DECE79C1B78082B0064D760 /* Images.xcassets */; }; 8DECE7A01B78082B0064D760 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8DECE79E1B78082B0064D760 /* LaunchScreen.xib */; }; @@ -27,13 +30,19 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 6B01EF851B7D1B34004151ED /* CQShadesData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CQShadesData.h; sourceTree = ""; }; + 6B01EF861B7D1B34004151ED /* CQShadesData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CQShadesData.m; sourceTree = ""; }; + 6B9A63F21B7A9D4E0025CD30 /* CategoriesRootViewTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CategoriesRootViewTableViewController.h; sourceTree = ""; }; + 6B9A63F31B7A9D4E0025CD30 /* CategoriesRootViewTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CategoriesRootViewTableViewController.m; sourceTree = ""; }; + 6B9A63F51B7A9DA20025CD30 /* ListTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ListTableViewController.h; sourceTree = ""; }; + 6B9A63F61B7A9DA20025CD30 /* ListTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ListTableViewController.m; sourceTree = ""; }; + 6BB571A11B7ADDBB0065EE52 /* CQCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CQCategory.h; sourceTree = ""; }; + 6BB571A21B7ADDBB0065EE52 /* CQCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CQCategory.m; sourceTree = ""; }; 8DECE78C1B78082B0064D760 /* OptionSelector.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OptionSelector.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8DECE7901B78082B0064D760 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 8DECE7911B78082B0064D760 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 8DECE7931B78082B0064D760 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 8DECE7941B78082B0064D760 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 8DECE7961B78082B0064D760 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - 8DECE7971B78082B0064D760 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 8DECE79A1B78082B0064D760 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 8DECE79C1B78082B0064D760 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 8DECE79F1B78082B0064D760 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; @@ -83,8 +92,14 @@ children = ( 8DECE7931B78082B0064D760 /* AppDelegate.h */, 8DECE7941B78082B0064D760 /* AppDelegate.m */, - 8DECE7961B78082B0064D760 /* ViewController.h */, - 8DECE7971B78082B0064D760 /* ViewController.m */, + 6B01EF851B7D1B34004151ED /* CQShadesData.h */, + 6B01EF861B7D1B34004151ED /* CQShadesData.m */, + 6BB571A11B7ADDBB0065EE52 /* CQCategory.h */, + 6BB571A21B7ADDBB0065EE52 /* CQCategory.m */, + 6B9A63F21B7A9D4E0025CD30 /* CategoriesRootViewTableViewController.h */, + 6B9A63F31B7A9D4E0025CD30 /* CategoriesRootViewTableViewController.m */, + 6B9A63F51B7A9DA20025CD30 /* ListTableViewController.h */, + 6B9A63F61B7A9DA20025CD30 /* ListTableViewController.m */, 8DECE7991B78082B0064D760 /* Main.storyboard */, 8DECE79C1B78082B0064D760 /* Images.xcassets */, 8DECE79E1B78082B0064D760 /* LaunchScreen.xib */, @@ -219,9 +234,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8DECE7981B78082B0064D760 /* ViewController.m in Sources */, 8DECE7951B78082B0064D760 /* AppDelegate.m in Sources */, + 6B9A63F41B7A9D4E0025CD30 /* CategoriesRootViewTableViewController.m in Sources */, + 6BB571A31B7ADDBB0065EE52 /* CQCategory.m in Sources */, + 6B01EF871B7D1B34004151ED /* CQShadesData.m in Sources */, 8DECE7921B78082B0064D760 /* main.m in Sources */, + 6B9A63F71B7A9DA20025CD30 /* ListTableViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -418,6 +436,7 @@ 8DECE7B11B78082B0064D760 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 8DECE7B21B78082B0064D760 /* Build configuration list for PBXNativeTarget "OptionSelectorTests" */ = { isa = XCConfigurationList; @@ -426,6 +445,7 @@ 8DECE7B41B78082B0064D760 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/OptionSelector/Base.lproj/Main.storyboard b/OptionSelector/Base.lproj/Main.storyboard index d912f9d..bdb6260 100644 --- a/OptionSelector/Base.lproj/Main.storyboard +++ b/OptionSelector/Base.lproj/Main.storyboard @@ -1,25 +1,102 @@ - + - + - - + + - - - - - - + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OptionSelector/CQCategory.h b/OptionSelector/CQCategory.h new file mode 100644 index 0000000..ad75dfd --- /dev/null +++ b/OptionSelector/CQCategory.h @@ -0,0 +1,26 @@ +// +// CQCategory.h +// OptionSelector +// +// Created by Justine Gartner on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import +#import + +//Model class for a category and it's related items/options. Every category has an array of options to choose from. Every array of options has a corresponding array of shade colors. Selected options and selected shade colors are selected by user. +@interface CQCategory : NSObject + +@property (nonatomic) NSString *name; +@property (nonatomic) NSString *detailTitle; +@property (nonatomic) NSArray *options; +@property (nonatomic) NSArray *shadeColors; +@property (nonatomic) NSString *selectedOption; +@property (nonatomic) UIColor *selectedShadeColor; + +-(void)saveSelection; + +-(void)loadDefaults; + +@end diff --git a/OptionSelector/CQCategory.m b/OptionSelector/CQCategory.m new file mode 100644 index 0000000..62b030f --- /dev/null +++ b/OptionSelector/CQCategory.m @@ -0,0 +1,47 @@ +// +// CQCategory.m +// OptionSelector +// +// Created by Justine Gartner on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#define SelectedOptionKey @"SelectedOptionName" +#define SelectedColorKey @"SelectedColor" + +#import "CQCategory.h" + +@implementation CQCategory + +-(void)saveSelection{ + + //archive the UIColor into NSData + NSData *colorData = [NSKeyedArchiver archivedDataWithRootObject:self.selectedShadeColor]; + + //create a dictionary with the selectedOption and selectedShadeColor + NSDictionary *data = @{SelectedOptionKey : self.selectedOption, + SelectedColorKey : colorData + }; + //store the dictionary in NSUserDefaults with the key: self.name + [[NSUserDefaults standardUserDefaults] setObject:data forKey:self.name]; + +} + +-(void)loadDefaults{ + + //load dictionary from NSUserDefaluts for the key: self.name + NSDictionary *data = [[NSUserDefaults standardUserDefaults] objectForKey:self.name]; + + //access the alue for the key color (NSData) + NSData *colorData = data[SelectedColorKey]; + + //convert the color data (NSData) to a color object (UIColor) + UIColor *color = [NSKeyedUnarchiver unarchiveObjectWithData:colorData]; + + if (data != nil) { + self.selectedOption = data[SelectedOptionKey]; + self.selectedShadeColor = color; + } +} + +@end diff --git a/OptionSelector/CQShadesData.h b/OptionSelector/CQShadesData.h new file mode 100644 index 0000000..b5312b4 --- /dev/null +++ b/OptionSelector/CQShadesData.h @@ -0,0 +1,22 @@ +// +// CQShadesData.h +// OptionSelector +// +// Created by Justine Gartner on 8/13/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import +#import "CQCategory.h" + + +//Initializes data for categories of shades from CQCategory class +@interface CQShadesData : NSObject + +@property (nonatomic) CQCategory *red; +@property (nonatomic) CQCategory *blue; +@property (nonatomic) CQCategory *yellow; + +-(void)initializeData; + +@end diff --git a/OptionSelector/CQShadesData.m b/OptionSelector/CQShadesData.m new file mode 100644 index 0000000..3daf7c8 --- /dev/null +++ b/OptionSelector/CQShadesData.m @@ -0,0 +1,233 @@ +// +// CQShadesData.m +// OptionSelector +// +// Created by Justine Gartner on 8/13/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "CQShadesData.h" +#import + +@implementation CQShadesData + ++ (UIColor *)makeColorWithRed:(NSInteger)red + green:(NSInteger)green + blue:(NSInteger)blue { + return [UIColor colorWithRed:red / 255.0 + green:green / 255.0 + blue:blue / 255.0 + alpha:1.0]; +} + + +-(void)initializeData{ + + self.red = [[CQCategory alloc] init]; + self.yellow = [[CQCategory alloc] init]; + self.blue = [[CQCategory alloc] init]; + + self.red.name = @"Red"; + self.yellow.name = @"Yellow"; + self.blue.name = @"Blue"; + + self.red.detailTitle = @"Shades of Red"; + self.yellow.detailTitle = @"Shades of Yellow"; + self.blue.detailTitle = @"Shades of Blue"; + + self.red.options = @[@"cherry", + @"rose", + @"jam", + @"merlot", + @"garnet", + @"crimson", + @"ruby", + @"scarlet", + @"wine", + @"brick", + @"apple", + @"mahogany", + @"blood", + @"sangria", + @"berry", + @"currant", + @"blush", + @"candy", + @"lipstick" + ]; + + self.yellow.options = @[@"canary", + @"gold", + @"daffodil", + @"flaxen", + @"butter", + @"lemon", + @"mustard", + @"corn", + @"medallion", + @"dandelion", + @"fire", + @"bumblebee", + @"banana", + @"butterscotch", + @"dijon", + @"honey", + @"blonde", + @"pineapple", + @"tuscan sun" + ]; + + self.blue.options = @[@"slate", + @"sky", + @"navy", + @"indigo", + @"cobalt", + @"teal", + @"ocean", + @"peacock", + @"azure", + @"cerulean", + @"lapis", + @"spruce", + @"stone", + @"aegean", + @"blueberry", + @"denim", + @"admiral", + @"sapphire", + @"arctic" + ]; + + + UIColor *cherry = [CQShadesData makeColorWithRed:164 green:0 blue:0]; + UIColor *rose = [CQShadesData makeColorWithRed:277 green:38 blue:54]; + UIColor *jam = [CQShadesData makeColorWithRed:195 green:33 blue:72]; + UIColor *merlot = [CQShadesData makeColorWithRed:112 green:28 blue:28]; + UIColor *garnet = [CQShadesData makeColorWithRed:128 green:0 blue:0]; + UIColor *crimson = [CQShadesData makeColorWithRed:178 green:34 blue:34]; + UIColor *ruby = [CQShadesData makeColorWithRed:206 green:32 blue:32]; + UIColor *scarlet = [CQShadesData makeColorWithRed:179 green:27 blue:27]; + UIColor *wine = [CQShadesData makeColorWithRed:86 green:3 blue:25]; + UIColor *brick = [CQShadesData makeColorWithRed:150 green:0 blue:24]; + UIColor *apple = [CQShadesData makeColorWithRed:227 green:0 blue:34]; + UIColor *mahogany = [CQShadesData makeColorWithRed:60 green:20 blue:20]; + UIColor *blood = [CQShadesData makeColorWithRed:128 green:0 blue:0]; + UIColor *sangria = [CQShadesData makeColorWithRed:128 green:0 blue:32]; + UIColor *berry = [CQShadesData makeColorWithRed:135 green:38 blue:87]; + UIColor *currant = [CQShadesData makeColorWithRed:101 green:0 blue:11]; + UIColor *blush = [CQShadesData makeColorWithRed:205 green:92 blue:92]; + UIColor *candy = [CQShadesData makeColorWithRed:255 green:8 blue:0]; + UIColor *lipstick = [CQShadesData makeColorWithRed:204 green:0 blue:0]; + + + self.red.shadeColors = @[cherry, + rose, + jam, + merlot, + garnet, + crimson, + ruby, + scarlet, + wine, + brick, + apple, + mahogany, + blood, + sangria, + berry, + currant, + blush, + candy, + lipstick + ]; + + UIColor *canary = [CQShadesData makeColorWithRed:255 green:191 blue:0]; + UIColor *gold = [CQShadesData makeColorWithRed:255 green:179 blue:71]; + UIColor *daffodil = [CQShadesData makeColorWithRed:247 green:233 blue:142]; + UIColor *flaxen = [CQShadesData makeColorWithRed:181 green:166 blue:66]; + UIColor *butter = [CQShadesData makeColorWithRed:255 green:248 blue:220]; + UIColor *lemon = [CQShadesData makeColorWithRed:255 green:247 blue:0]; + UIColor *mustard = [CQShadesData makeColorWithRed:255 green:219 blue:88]; + UIColor *corn = [CQShadesData makeColorWithRed:233 green:214 blue:107]; + UIColor *medallion = [CQShadesData makeColorWithRed:218 green:165 blue:32]; + UIColor *dandelion = [CQShadesData makeColorWithRed:255 green:209 blue:42]; + UIColor *fire = [CQShadesData makeColorWithRed:228 green:155 blue:15]; + UIColor *bumblebee = [CQShadesData makeColorWithRed:236 green:213 blue:64]; + UIColor *banana = [CQShadesData makeColorWithRed:255 green:225 blue:53]; + UIColor *butterscotch = [CQShadesData makeColorWithRed:244 green:196 blue:48]; + UIColor *dijon = [CQShadesData makeColorWithRed:184 green:134 blue:11]; + UIColor *honey = [CQShadesData makeColorWithRed:240 green:220 blue:130]; + UIColor *blonde = [CQShadesData makeColorWithRed:250 green:240 blue:190]; + UIColor *pineapple = [CQShadesData makeColorWithRed:251 green:236 blue:93]; + UIColor *tuscanSun = [CQShadesData makeColorWithRed:255 green:223 blue:0]; + + + self.yellow.shadeColors = @[canary, + gold, + daffodil, + flaxen, + butter, + lemon, + mustard, + corn, + medallion, + dandelion, + fire, + bumblebee, + banana, + butterscotch, + dijon, + honey, + blonde, + pineapple, + tuscanSun + ]; + + UIColor *slate = [CQShadesData makeColorWithRed:112 green:128 blue:144]; + UIColor *sky = [CQShadesData makeColorWithRed:135 green:206 blue:235]; + UIColor *navy = [CQShadesData makeColorWithRed:0 green:0 blue:128]; + UIColor *indigo = [CQShadesData makeColorWithRed:75 green:0 blue:130]; + UIColor *cobalt = [CQShadesData makeColorWithRed:0 green:71 blue:171]; + UIColor *teal = [CQShadesData makeColorWithRed:0 green:128 blue:128]; + UIColor *ocean = [CQShadesData makeColorWithRed:47 green:79 blue:79]; + UIColor *peacock = [CQShadesData makeColorWithRed:47 green:47 blue:79]; + UIColor *azure = [CQShadesData makeColorWithRed:0 green:51 blue:153]; + UIColor *cerulean = [CQShadesData makeColorWithRed:0 green:123 blue:167]; + UIColor *lapis = [CQShadesData makeColorWithRed:21 green:96 blue:89]; + UIColor *spruce = [CQShadesData makeColorWithRed:117 green:133 blue:123]; + UIColor *stone = [CQShadesData makeColorWithRed:83 green:104 blue:120]; + UIColor *aegean = [CQShadesData makeColorWithRed:8 green:69 blue:126]; + UIColor *blueberry = [CQShadesData makeColorWithRed:25 green:25 blue:112]; + UIColor *denim = [CQShadesData makeColorWithRed:0 green:35 blue:102]; + UIColor *admiral = [CQShadesData makeColorWithRed:0 green:0 blue:156]; + UIColor *sapphire = [CQShadesData makeColorWithRed:18 green:97 blue:128]; + UIColor *arctic = [CQShadesData makeColorWithRed:231 green:254 blue:255]; + + self.blue.shadeColors = @[slate, + sky, + navy, + indigo, + cobalt, + teal, + ocean, + peacock, + azure, + cerulean, + lapis, + spruce, + stone, + aegean, + blueberry, + denim, + admiral, + sapphire, + arctic + ]; + + [self.red loadDefaults]; + [self.blue loadDefaults]; + [self.yellow loadDefaults]; + +} + +@end diff --git a/OptionSelector/CategoriesRootViewTableViewController.h b/OptionSelector/CategoriesRootViewTableViewController.h new file mode 100644 index 0000000..18de7ae --- /dev/null +++ b/OptionSelector/CategoriesRootViewTableViewController.h @@ -0,0 +1,13 @@ +// +// CategoriesRootViewTableViewController.h +// OptionSelector +// +// Created by Justine Gartner on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface CategoriesRootViewTableViewController : UITableViewController + +@end diff --git a/OptionSelector/CategoriesRootViewTableViewController.m b/OptionSelector/CategoriesRootViewTableViewController.m new file mode 100644 index 0000000..1b73a29 --- /dev/null +++ b/OptionSelector/CategoriesRootViewTableViewController.m @@ -0,0 +1,98 @@ +// +// CategoriesRootViewTableViewController.m +// OptionSelector +// +// Created by Justine Gartner on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "CategoriesRootViewTableViewController.h" +#import "ListTableViewController.h" +#import "CQCategory.h" +#import "CQShadesData.h" + +@interface CategoriesRootViewTableViewController () + +@property (nonatomic)CQShadesData *model; + +@property (nonatomic)NSArray *data; + +@end + +@implementation CategoriesRootViewTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.model = [[CQShadesData alloc] init]; + + [self.model initializeData]; + + self.data = @[self.model.red, self.model.yellow, self.model.blue]; + + self.navigationItem.title = @"Shades"; + +} + +#pragma mark - Table view data source + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + + return self.data.count; +} + + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ColorThesaurusIdentifier" forIndexPath:indexPath]; + + CQCategory *c = self.data [indexPath.row]; + + cell.textLabel.text = c.name; + + //If there was no initial text on the detailTextLabel then the label would have 0 width/0 height, thereby making the detailTextLabel non-existent. Not sure why this was happening... + //By setting an empty space as default it sizes correctly + + if (c.selectedOption) { + NSLog(@"Valid selected value"); + cell.detailTextLabel.text = c.selectedOption; + cell.backgroundColor = c.selectedShadeColor; + cell.textLabel.textColor = [UIColor lightGrayColor]; + } else { + cell.detailTextLabel.text = @" "; + + } + + UIFont *myFont = [ UIFont fontWithName: @"Marion" size: 25.0 ]; + cell.textLabel.font = myFont; + + return cell; +} + +-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ + + NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; + + ListTableViewController *listOfShadesViewController = segue.destinationViewController; + listOfShadesViewController.basic = self.data[indexPath.row]; + listOfShadesViewController.selectedBasicIndexPath = indexPath; + listOfShadesViewController.delegate = self; +} + +#pragma ListTableViewControllerDelegate + +-(void) didSelectShade: (NSString *)shade withColor: (UIColor *)color atIndexPath: (NSIndexPath *) indexPath{ + + CQCategory *category = self.data[indexPath.row]; + + category.selectedOption = shade; + category.selectedShadeColor = color; + + [category saveSelection]; + + [self.tableView reloadData]; + + NSLog(@"Did select shade: %@", shade); +} + + +@end diff --git a/OptionSelector/ListTableViewController.h b/OptionSelector/ListTableViewController.h new file mode 100644 index 0000000..fb516fb --- /dev/null +++ b/OptionSelector/ListTableViewController.h @@ -0,0 +1,26 @@ +// +// ListTableViewController.h +// OptionSelector +// +// Created by Justine Gartner on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import +#import "CQCategory.h" + +@protocol ListTableViewControllerDelegate + +-(void) didSelectShade: (NSString *)shade withColor: (UIColor *)color atIndexPath: (NSIndexPath *) indexPath; + +@end + +@interface ListTableViewController : UITableViewController + +@property (nonatomic) CQCategory *basic; +@property (nonatomic, weak) id delegate; + +@property (nonatomic) NSIndexPath *selectedBasicIndexPath; + +@end + diff --git a/OptionSelector/ListTableViewController.m b/OptionSelector/ListTableViewController.m new file mode 100644 index 0000000..7468f8a --- /dev/null +++ b/OptionSelector/ListTableViewController.m @@ -0,0 +1,83 @@ +// +// ListTableViewController.m +// OptionSelector +// +// Created by Justine Gartner on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + + +#import "ListTableViewController.h" + +@interface ListTableViewController () + +@end + +@implementation ListTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.title = self.basic.detailTitle; +} + + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + + return self.basic.options.count; +} + + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListOfShadesCellIdentifier" forIndexPath:indexPath]; + + NSArray *listOfShades = self.basic.options; + NSString *shadeName = listOfShades [indexPath.row]; + + cell.textLabel.text = shadeName; + + UIFont *myFont = [UIFont fontWithName: @"Marion" size: 17.0 ]; + cell.textLabel.font = myFont; + + return cell; +} + +-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ + + UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; + + cell.accessoryType = UITableViewCellAccessoryCheckmark; + + NSArray *listOfShades = self.basic.options; + NSString *selectedShade = listOfShades [indexPath.row]; + + NSArray *colorOfShades = self.basic.shadeColors; + UIColor *selectedColor = colorOfShades [indexPath.row]; + + cell.contentView.backgroundColor = selectedColor; + + [self.delegate didSelectShade:selectedShade withColor:selectedColor atIndexPath: self.selectedBasicIndexPath]; + + NSLog(@"Selected: %@", selectedShade); + + + +} + +-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; + + cell.accessoryType = UITableViewCellAccessoryNone; + + cell.contentView.backgroundColor = [UIColor whiteColor]; + +} + +@end diff --git a/OptionSelector/ViewController.h b/OptionSelector/ViewController.h deleted file mode 100644 index 6b5159f..0000000 --- a/OptionSelector/ViewController.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// ViewController.h -// OptionSelector -// -// Created by Michael Kavouras on 8/9/15. -// Copyright (c) 2015 Mike Kavouras. All rights reserved. -// - -#import - -@interface ViewController : UIViewController - - -@end - diff --git a/OptionSelector/ViewController.m b/OptionSelector/ViewController.m deleted file mode 100644 index 8c74bbb..0000000 --- a/OptionSelector/ViewController.m +++ /dev/null @@ -1,27 +0,0 @@ -// -// ViewController.m -// OptionSelector -// -// Created by Michael Kavouras on 8/9/15. -// Copyright (c) 2015 Mike Kavouras. All rights reserved. -// - -#import "ViewController.h" - -@interface ViewController () - -@end - -@implementation ViewController - -- (void)viewDidLoad { - [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. -} - -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - -@end