diff --git a/OptionSelector.xcodeproj/project.pbxproj b/OptionSelector.xcodeproj/project.pbxproj index 1788504..243a023 100644 --- a/OptionSelector.xcodeproj/project.pbxproj +++ b/OptionSelector.xcodeproj/project.pbxproj @@ -7,9 +7,12 @@ objects = { /* Begin PBXBuildFile section */ + 45F503151B7AAA2E004C5DD4 /* SummaryTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 45F503141B7AAA2E004C5DD4 /* SummaryTableViewController.m */; }; + 45F503181B7AAA69004C5DD4 /* OptionsSelectTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 45F503171B7AAA69004C5DD4 /* OptionsSelectTableViewController.m */; }; + 45F5031B1B7AAD8C004C5DD4 /* ListData.m in Sources */ = {isa = PBXBuildFile; fileRef = 45F5031A1B7AAD8C004C5DD4 /* ListData.m */; }; + 45F503501B7C71BB004C5DD4 /* ListInstance.m in Sources */ = {isa = PBXBuildFile; fileRef = 45F5034F1B7C71BB004C5DD4 /* ListInstance.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,20 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 45F503101B7AA9F9004C5DD4 /* SummaryTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SummaryTableViewController.h; sourceTree = ""; }; + 45F503131B7AAA2E004C5DD4 /* SummaryTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SummaryTableViewController.h; sourceTree = ""; }; + 45F503141B7AAA2E004C5DD4 /* SummaryTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SummaryTableViewController.m; sourceTree = ""; }; + 45F503161B7AAA69004C5DD4 /* OptionsSelectTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OptionsSelectTableViewController.h; sourceTree = ""; }; + 45F503171B7AAA69004C5DD4 /* OptionsSelectTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OptionsSelectTableViewController.m; sourceTree = ""; }; + 45F503191B7AAD8C004C5DD4 /* ListData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ListData.h; sourceTree = ""; }; + 45F5031A1B7AAD8C004C5DD4 /* ListData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ListData.m; sourceTree = ""; }; + 45F5034E1B7C71BB004C5DD4 /* ListInstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ListInstance.h; sourceTree = ""; }; + 45F5034F1B7C71BB004C5DD4 /* ListInstance.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ListInstance.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 = ""; }; @@ -63,6 +73,7 @@ 8DECE7831B78082B0064D760 = { isa = PBXGroup; children = ( + 45F503101B7AA9F9004C5DD4 /* SummaryTableViewController.h */, 8DECE78E1B78082B0064D760 /* OptionSelector */, 8DECE7A81B78082B0064D760 /* OptionSelectorTests */, 8DECE78D1B78082B0064D760 /* Products */, @@ -83,8 +94,14 @@ children = ( 8DECE7931B78082B0064D760 /* AppDelegate.h */, 8DECE7941B78082B0064D760 /* AppDelegate.m */, - 8DECE7961B78082B0064D760 /* ViewController.h */, - 8DECE7971B78082B0064D760 /* ViewController.m */, + 45F503191B7AAD8C004C5DD4 /* ListData.h */, + 45F5031A1B7AAD8C004C5DD4 /* ListData.m */, + 45F5034E1B7C71BB004C5DD4 /* ListInstance.h */, + 45F5034F1B7C71BB004C5DD4 /* ListInstance.m */, + 45F503131B7AAA2E004C5DD4 /* SummaryTableViewController.h */, + 45F503141B7AAA2E004C5DD4 /* SummaryTableViewController.m */, + 45F503161B7AAA69004C5DD4 /* OptionsSelectTableViewController.h */, + 45F503171B7AAA69004C5DD4 /* OptionsSelectTableViewController.m */, 8DECE7991B78082B0064D760 /* Main.storyboard */, 8DECE79C1B78082B0064D760 /* Images.xcassets */, 8DECE79E1B78082B0064D760 /* LaunchScreen.xib */, @@ -219,8 +236,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8DECE7981B78082B0064D760 /* ViewController.m in Sources */, + 45F503181B7AAA69004C5DD4 /* OptionsSelectTableViewController.m in Sources */, 8DECE7951B78082B0064D760 /* AppDelegate.m in Sources */, + 45F503151B7AAA2E004C5DD4 /* SummaryTableViewController.m in Sources */, + 45F5031B1B7AAD8C004C5DD4 /* ListData.m in Sources */, + 45F503501B7C71BB004C5DD4 /* ListInstance.m in Sources */, 8DECE7921B78082B0064D760 /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -418,6 +438,7 @@ 8DECE7B11B78082B0064D760 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 8DECE7B21B78082B0064D760 /* Build configuration list for PBXNativeTarget "OptionSelectorTests" */ = { isa = XCConfigurationList; @@ -426,6 +447,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..80840d4 100644 --- a/OptionSelector/Base.lproj/Main.storyboard +++ b/OptionSelector/Base.lproj/Main.storyboard @@ -1,25 +1,94 @@ - + - + - - + + - - - - - - + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OptionSelector/ListData.h b/OptionSelector/ListData.h new file mode 100644 index 0000000..e98ec04 --- /dev/null +++ b/OptionSelector/ListData.h @@ -0,0 +1,18 @@ +// +// ListData.h +// OptionSelector +// +// Created by Chris David on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface ListData : NSObject + +@property (nonatomic) NSString *name; +@property (nonatomic) NSString *selection; +@property (nonatomic) NSArray *options; +@property (nonatomic) NSUInteger index; + +@end diff --git a/OptionSelector/ListData.m b/OptionSelector/ListData.m new file mode 100644 index 0000000..4033dd2 --- /dev/null +++ b/OptionSelector/ListData.m @@ -0,0 +1,13 @@ +// +// ListData.m +// OptionSelector +// +// Created by Chris David on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "ListData.h" + +@implementation ListData + +@end diff --git a/OptionSelector/ListInstance.h b/OptionSelector/ListInstance.h new file mode 100644 index 0000000..fd82eea --- /dev/null +++ b/OptionSelector/ListInstance.h @@ -0,0 +1,19 @@ +// +// ListInstance.h +// OptionSelector +// +// Created by Chris David on 8/13/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface ListInstance : NSObject + +@property (nonatomic) NSMutableArray *allCategories; + +-(void) initializeModel; + ++ (ListInstance *)sharedInstance; + +@end diff --git a/OptionSelector/ListInstance.m b/OptionSelector/ListInstance.m new file mode 100644 index 0000000..258bc64 --- /dev/null +++ b/OptionSelector/ListInstance.m @@ -0,0 +1,54 @@ +// +// ListInstance.m +// OptionSelector +// +// Created by Chris David on 8/13/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "ListInstance.h" +#import "ListData.h" + +@implementation ListInstance + ++ (ListInstance *)sharedInstance +{ + static dispatch_once_t once; + static id sharedInstance; + dispatch_once(&once, ^{ + sharedInstance = [[self alloc] init]; + }); + return sharedInstance; +} + +-(void) initializeModel { + + self.allCategories = [[NSMutableArray alloc] init]; + + ListData *basketball = [[ListData alloc] init]; + basketball.name = @"Basketball"; + basketball.selection = @""; + basketball.options = @[@"Knicks", @"Heat", @"Celtics", @"Warriors", @"Nets", @"Timberwolves"]; + basketball.index = 0; + [self.allCategories addObject:basketball]; + + ListData * baseball = [[ListData alloc] init]; + baseball.name = @"Baseball"; + baseball.selection = @""; + baseball.options = @[@"Yankees", @"Mets", @"Red Sox", @"Twins", @"Dodgers"]; + baseball.index = 1; + [self.allCategories addObject:baseball]; + + ListData * football = [[ListData alloc] init]; + football.name = @"Football"; + football.selection = @""; + football.options = @[@"Giants", @"Jets", @"Eagles", @"Colts", @"Patriots"]; + football.index = 2; + [self.allCategories addObject:football]; + + + +} + + +@end diff --git a/OptionSelector/OptionsSelectTableViewController.h b/OptionSelector/OptionsSelectTableViewController.h new file mode 100644 index 0000000..f105809 --- /dev/null +++ b/OptionSelector/OptionsSelectTableViewController.h @@ -0,0 +1,16 @@ +// +// OptionsSelectTableViewController.h +// OptionSelector +// +// Created by Chris David on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import +#import "ListData.h" + +@interface OptionsSelectTableViewController : UITableViewController + +@property (nonatomic) ListData * category; + +@end diff --git a/OptionSelector/OptionsSelectTableViewController.m b/OptionSelector/OptionsSelectTableViewController.m new file mode 100644 index 0000000..c598669 --- /dev/null +++ b/OptionSelector/OptionsSelectTableViewController.m @@ -0,0 +1,61 @@ +// +// OptionsSelectTableViewController.m +// OptionSelector +// +// Created by Chris David on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "OptionsSelectTableViewController.h" +#import "ListInstance.h" +#import "ListData.h" + +@interface OptionsSelectTableViewController () + +@end + +@implementation OptionsSelectTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return [self.category.options count]; +} + + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OptionsCellIdentifier" forIndexPath:indexPath]; + + cell.textLabel.text = [self.category.options objectAtIndex:indexPath.row]; + + return cell; +} +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; + ListInstance *shared = [ListInstance sharedInstance]; + NSString *picked = [self.category.options objectAtIndex: indexPath.row]; + + self.category.selection = picked; + + [shared.allCategories replaceObjectAtIndex:self.category.index withObject:self.category]; +} + +-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone; +} + +@end diff --git a/OptionSelector/SummaryTableViewController.h b/OptionSelector/SummaryTableViewController.h new file mode 100644 index 0000000..fa7f59f --- /dev/null +++ b/OptionSelector/SummaryTableViewController.h @@ -0,0 +1,13 @@ +// +// SummaryTableViewController.h +// OptionSelector +// +// Created by Chris David on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface SummaryTableViewController : UITableViewController + +@end diff --git a/OptionSelector/SummaryTableViewController.m b/OptionSelector/SummaryTableViewController.m new file mode 100644 index 0000000..97fefd5 --- /dev/null +++ b/OptionSelector/SummaryTableViewController.m @@ -0,0 +1,72 @@ +// +// SummaryTableViewController.m +// OptionSelector +// +// Created by Chris David on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "SummaryTableViewController.h" +#import "ListInstance.h" +#import "ListData.h" +#import "OptionsSelectTableViewController.h" + +@interface SummaryTableViewController () + +@property (nonatomic) ListInstance * data; + +@end + +@implementation SummaryTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.title = @"Favorite Sports Team"; + self.data = [ListInstance sharedInstance]; + [self.data initializeModel]; + +} + +- (void)viewDidAppear:(BOOL)animated { + [self.tableView reloadData]; +} +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return [self.data.allCategories count]; +} + + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CategoryCellIdentifier" forIndexPath:indexPath]; + + ListData * category = [self.data.allCategories objectAtIndex:indexPath.row]; + + NSString * title = category.name; + NSString * selected = category.selection; + cell.textLabel.text = title; + + cell.detailTextLabel.text = selected; + + + return cell; +} + +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + NSIndexPath * indexPath = [self.tableView indexPathForSelectedRow]; + ListData * selected = [self.data.allCategories objectAtIndex:indexPath.row]; + OptionsSelectTableViewController * destination = segue.destinationViewController; + destination.category = selected; +} + + +@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 diff --git a/SummaryTableViewController.h b/SummaryTableViewController.h new file mode 100644 index 0000000..fa7f59f --- /dev/null +++ b/SummaryTableViewController.h @@ -0,0 +1,13 @@ +// +// SummaryTableViewController.h +// OptionSelector +// +// Created by Chris David on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface SummaryTableViewController : UITableViewController + +@end