From e5b9661a3ac0e8decc7455539f4262a46dbed0d9 Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 14 Aug 2015 21:16:54 -0400 Subject: [PATCH] first commit --- CQCategory.h | 19 ++ CQCategory.m | 21 +++ OptionSelector.xcodeproj/project.pbxproj | 32 +++- .../AnimalDetailTableViewController.h | 29 +++ .../AnimalDetailTableViewController.m | 91 +++++++++ .../AnimalTypesTableViewController.h | 15 ++ .../AnimalTypesTableViewController.m | 178 ++++++++++++++++++ OptionSelector/Base.lproj/Main.storyboard | 99 ++++++++-- OptionSelector/NavigationViewController.h | 13 ++ OptionSelector/NavigationViewController.m | 37 ++++ OptionSelector/ViewController.h | 15 -- OptionSelector/ViewController.m | 27 --- 12 files changed, 513 insertions(+), 63 deletions(-) create mode 100644 CQCategory.h create mode 100644 CQCategory.m create mode 100644 OptionSelector/AnimalDetailTableViewController.h create mode 100644 OptionSelector/AnimalDetailTableViewController.m create mode 100644 OptionSelector/AnimalTypesTableViewController.h create mode 100644 OptionSelector/AnimalTypesTableViewController.m create mode 100644 OptionSelector/NavigationViewController.h create mode 100644 OptionSelector/NavigationViewController.m delete mode 100644 OptionSelector/ViewController.h delete mode 100644 OptionSelector/ViewController.m diff --git a/CQCategory.h b/CQCategory.h new file mode 100644 index 0000000..4f8331a --- /dev/null +++ b/CQCategory.h @@ -0,0 +1,19 @@ +// +// CQCategory.h +// OptionSelector +// +// Created by Lauren Caponong on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface CQCategory : NSObject + +@property (nonatomic) NSString *name; +@property (nonatomic) NSArray *options; +@property (nonatomic) NSString *selection; + +- (void)initializeData; + +@end diff --git a/CQCategory.m b/CQCategory.m new file mode 100644 index 0000000..3bfa9a6 --- /dev/null +++ b/CQCategory.m @@ -0,0 +1,21 @@ +// +// CQCategory.m +// OptionSelector +// +// Created by Lauren Caponong on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "CQCategory.h" + +@implementation CQCategory + +- (void)initializeData { + + [self name]; + [self options]; + [self selection]; +} + + +@end diff --git a/OptionSelector.xcodeproj/project.pbxproj b/OptionSelector.xcodeproj/project.pbxproj index 1788504..551967c 100644 --- a/OptionSelector.xcodeproj/project.pbxproj +++ b/OptionSelector.xcodeproj/project.pbxproj @@ -7,9 +7,12 @@ objects = { /* Begin PBXBuildFile section */ + 898EFF241B7AD61E00A30F21 /* NavigationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 898EFF231B7AD61E00A30F21 /* NavigationViewController.m */; }; + 898EFF271B7AD63D00A30F21 /* AnimalDetailTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 898EFF261B7AD63D00A30F21 /* AnimalDetailTableViewController.m */; }; + 898EFF2A1B7AD65E00A30F21 /* AnimalTypesTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 898EFF291B7AD65E00A30F21 /* AnimalTypesTableViewController.m */; }; + 898EFF301B7AD82F00A30F21 /* CQCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = 898EFF2F1B7AD82F00A30F21 /* 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 */ + 898EFF221B7AD61E00A30F21 /* NavigationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigationViewController.h; sourceTree = ""; }; + 898EFF231B7AD61E00A30F21 /* NavigationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationViewController.m; sourceTree = ""; }; + 898EFF251B7AD63D00A30F21 /* AnimalDetailTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnimalDetailTableViewController.h; sourceTree = ""; }; + 898EFF261B7AD63D00A30F21 /* AnimalDetailTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnimalDetailTableViewController.m; sourceTree = ""; }; + 898EFF281B7AD65E00A30F21 /* AnimalTypesTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnimalTypesTableViewController.h; sourceTree = ""; }; + 898EFF291B7AD65E00A30F21 /* AnimalTypesTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnimalTypesTableViewController.m; sourceTree = ""; }; + 898EFF2E1B7AD82F00A30F21 /* CQCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CQCategory.h; path = ../CQCategory.h; sourceTree = ""; }; + 898EFF2F1B7AD82F00A30F21 /* CQCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CQCategory.m; 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 */, + 898EFF221B7AD61E00A30F21 /* NavigationViewController.h */, + 898EFF231B7AD61E00A30F21 /* NavigationViewController.m */, + 898EFF2E1B7AD82F00A30F21 /* CQCategory.h */, + 898EFF2F1B7AD82F00A30F21 /* CQCategory.m */, + 898EFF281B7AD65E00A30F21 /* AnimalTypesTableViewController.h */, + 898EFF291B7AD65E00A30F21 /* AnimalTypesTableViewController.m */, + 898EFF251B7AD63D00A30F21 /* AnimalDetailTableViewController.h */, + 898EFF261B7AD63D00A30F21 /* AnimalDetailTableViewController.m */, 8DECE7991B78082B0064D760 /* Main.storyboard */, 8DECE79C1B78082B0064D760 /* Images.xcassets */, 8DECE79E1B78082B0064D760 /* LaunchScreen.xib */, @@ -219,9 +234,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8DECE7981B78082B0064D760 /* ViewController.m in Sources */, + 898EFF271B7AD63D00A30F21 /* AnimalDetailTableViewController.m in Sources */, + 898EFF301B7AD82F00A30F21 /* CQCategory.m in Sources */, 8DECE7951B78082B0064D760 /* AppDelegate.m in Sources */, + 898EFF2A1B7AD65E00A30F21 /* AnimalTypesTableViewController.m in Sources */, 8DECE7921B78082B0064D760 /* main.m in Sources */, + 898EFF241B7AD61E00A30F21 /* NavigationViewController.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/AnimalDetailTableViewController.h b/OptionSelector/AnimalDetailTableViewController.h new file mode 100644 index 0000000..b869f04 --- /dev/null +++ b/OptionSelector/AnimalDetailTableViewController.h @@ -0,0 +1,29 @@ +// +// AnimalDetailTableViewController.h +// OptionSelector +// +// Created by Lauren Caponong on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import +#import "CQCategory.h" + +@class AnimalDetailTableViewController; + +@protocol ViewControllerAnimalDetailTableViewDelegate +- (void)addItemViewController:(AnimalDetailTableViewController *)controller didFinishEnteringItem:(CQCategory *)item; +@end + + + + +@interface AnimalDetailTableViewController : UITableViewController + +@property (nonatomic) CQCategory *thing; +@property (nonatomic, weak) id delegate; + +@property (nonatomic, retain) NSString *selectedThing; + + +@end diff --git a/OptionSelector/AnimalDetailTableViewController.m b/OptionSelector/AnimalDetailTableViewController.m new file mode 100644 index 0000000..f67b38b --- /dev/null +++ b/OptionSelector/AnimalDetailTableViewController.m @@ -0,0 +1,91 @@ +// +// AnimalDetailTableViewController.m +// OptionSelector +// +// Created by Lauren Caponong on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "AnimalDetailTableViewController.h" +#import "CQCategory.h" + +@interface AnimalDetailTableViewController () + +@property (nonatomic) NSMutableArray *array2; + + +@end + + + + +@implementation AnimalDetailTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + + CQCategory *dog = [[CQCategory alloc] init]; + CQCategory *cat = [[CQCategory alloc] init]; + CQCategory *bug = [[CQCategory alloc] init]; + + dog.name = @"Dog"; + cat.name = @"Cat"; + bug.name = @"Bug"; + + [self.array2 addObject:dog]; + [self.array2 addObject:cat]; + [self.array2 addObject:bug]; + + +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.thing.options.count; +} + + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AnimalTypesIdentifier2" forIndexPath:indexPath]; + + NSString *name = self.thing.options[indexPath.row]; + + cell.textLabel.text = name; + + NSString *itemToPassBack = @"PASS"; + [self.delegate addItemViewController:self didFinishEnteringItem:itemToPassBack]; + + return cell; +} + + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; + + self.thing.selection = self.thing.options[indexPath.row]; + + [self.delegate addItemViewController:self didFinishEnteringItem:self.thing]; + +} + +-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone; +} + + + + +@end diff --git a/OptionSelector/AnimalTypesTableViewController.h b/OptionSelector/AnimalTypesTableViewController.h new file mode 100644 index 0000000..0a6736e --- /dev/null +++ b/OptionSelector/AnimalTypesTableViewController.h @@ -0,0 +1,15 @@ +// +// AnimalTypesTableViewController.h +// OptionSelector +// +// Created by Lauren Caponong on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import +#import "AnimalDetailTableViewController.h" + + +@interface AnimalTypesTableViewController : UITableViewController + +@end diff --git a/OptionSelector/AnimalTypesTableViewController.m b/OptionSelector/AnimalTypesTableViewController.m new file mode 100644 index 0000000..ac9ecf5 --- /dev/null +++ b/OptionSelector/AnimalTypesTableViewController.m @@ -0,0 +1,178 @@ +// +// AnimalTypesTableViewController.m +// OptionSelector +// +// Created by Lauren Caponong on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "AnimalTypesTableViewController.h" +#import "AnimalDetailTableViewController.h" +#import "CQCategory.h" + +@interface AnimalTypesTableViewController () + +@property (nonatomic) NSMutableArray *array; +@property (nonatomic) NSInteger index; + +@end + + + + +@implementation AnimalTypesTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + + + // initialize the array to hold our types - dog, cat, bug + + self.array = [[NSMutableArray alloc]init]; + + + + // creating instances of CQCategory and initializing them + + CQCategory *dog = [[CQCategory alloc] init]; + CQCategory *cat = [[CQCategory alloc] init]; + CQCategory *bug = [[CQCategory alloc] init]; + + + + // the 'name' property of the dog, cat, bug instances of CQCategory will be those strings + + dog.name = @"Dog"; + cat.name = @"Cat"; + bug.name = @"Bug"; + + + + // breeds of dog - these are our options to choose from + + dog.options = @[ + @"Golden Retriever", + @"Yorkie", + @"Alaskan Malamute", + @"Pug", + @"Bulldog", + @"Bernese Mountain Dog", + @"Labrador Retriver", + @"Mastiff"]; + dog.selection = @" "; + + + + + + // breeds of cat - these are our options to choose from + + cat.options = @[ + @"Russian Blue", + @"Calico", + @"Siamese", + @"British Shorthair", + @"Persian", + @"Cornish Rex", + @"Scottish Fold"]; + + cat.selection = @" "; + + + + + + // breeds of bug - these are our options to choose from + + bug.options = @[ + @"Butterfly", + @"Ladybug", + @"Caterpillar", + @"Spider", + @"Dragonfly", + @"Cricket"]; + + bug.selection = @" "; + + + + // adding these CQCategory instancse - dog, cat, bug - to our array to hold the 'types' of animal + + [self.array addObject:dog]; + [self.array addObject:cat]; + [self.array addObject:bug]; + +} + +- (void)viewWillAppear:(BOOL)animated{ + [super viewWillAppear:animated]; + [self.tableView reloadData]; +} +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + + +- (void)addItemViewController:(AnimalDetailTableViewController *)controller didFinishEnteringItem:(CQCategory *)item{ + + [self.array replaceObjectAtIndex:self.index withObject:item]; + +} + + + + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.array.count; +} + + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AnimalTypesIdentifier" forIndexPath:indexPath]; + + CQCategory *object = [self.array objectAtIndex:indexPath.row]; + NSString *name = object.name; + + cell.textLabel.text = name; + cell.detailTextLabel.text = [object.selection isEqualToString:@" "]?@" ":object.selection; + return cell; +} + + +#pragma mark - Navigation + + +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + + NSLog(@"You clicked on an animal with a specific breed."); + + NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; + + + AnimalDetailTableViewController *detailViewController = segue.destinationViewController; + + self.index = indexPath.row; + + if (indexPath.row == 0) { + CQCategory *dog = self.array[indexPath.row]; + detailViewController.thing = dog; + } else if (indexPath.row == 1) { + CQCategory *cat = self.array[indexPath.row]; + detailViewController.thing = cat; + } else if (indexPath.row == 2) { + CQCategory *bug = self.array[indexPath.row]; + detailViewController.thing = bug; + } + +} + + +@end diff --git a/OptionSelector/Base.lproj/Main.storyboard b/OptionSelector/Base.lproj/Main.storyboard index d912f9d..c1fa597 100644 --- a/OptionSelector/Base.lproj/Main.storyboard +++ b/OptionSelector/Base.lproj/Main.storyboard @@ -1,25 +1,94 @@ - + - + - - + + - - - - - - + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OptionSelector/NavigationViewController.h b/OptionSelector/NavigationViewController.h new file mode 100644 index 0000000..b2f7ad9 --- /dev/null +++ b/OptionSelector/NavigationViewController.h @@ -0,0 +1,13 @@ +// +// NavigationViewController.h +// OptionSelector +// +// Created by Lauren Caponong on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface NavigationViewController : UINavigationController + +@end diff --git a/OptionSelector/NavigationViewController.m b/OptionSelector/NavigationViewController.m new file mode 100644 index 0000000..7c4bea6 --- /dev/null +++ b/OptionSelector/NavigationViewController.m @@ -0,0 +1,37 @@ +// +// NavigationViewController.m +// OptionSelector +// +// Created by Lauren Caponong on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "NavigationViewController.h" + +@interface NavigationViewController () + +@end + +@implementation NavigationViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view. +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ + +@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