diff --git a/DetailTableViewController.h b/DetailTableViewController.h new file mode 100644 index 0000000..5b11cd7 --- /dev/null +++ b/DetailTableViewController.h @@ -0,0 +1,18 @@ +// +// DetailTableViewController.h +// OptionSelector +// +// Created by Kaisha Jones on 9/12/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import +#import "CQCategory.h" + + +@interface DetailTableViewController : UITableViewController + +@property (nonatomic,retain) NSIndexPath *checkedIndexPath; +@property (nonatomic) CQCategory *category; + +@end diff --git a/DetailTableViewController.m b/DetailTableViewController.m new file mode 100644 index 0000000..d591a76 --- /dev/null +++ b/DetailTableViewController.m @@ -0,0 +1,75 @@ +// +// DetailTableViewController.m +// OptionSelector +// +// Created by Kaisha Jones on 9/12/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import "DetailTableViewController.h" + +@interface DetailTableViewController () + +@end + + + +@implementation DetailTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // set checked index path to initial value (needs to reference the selected option) +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + // Return the number of sections. + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.category.options.count; // display each category's options "sad, bliss, etc" +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailIdentifier" forIndexPath:indexPath]; + + NSString *optionName = [self.category.options objectAtIndex:indexPath.row]; // configure string to show in view + cell.textLabel.text = optionName; + + if([self.category.options[indexPath.row] isEqualToString:self.category.selection]){ // added to retain selection + cell.accessoryType = UITableViewCellAccessoryCheckmark; + self.checkedIndexPath = indexPath; // added: only one checkmark is allowed! + } + return cell; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + // add check marks + [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; + + // to only select one item in the array + if(self.checkedIndexPath) { + UITableViewCell* uncheckCell = [tableView cellForRowAtIndexPath:self.checkedIndexPath]; + uncheckCell.accessoryType = UITableViewCellAccessoryNone; + } + + if([self.checkedIndexPath isEqual:indexPath]) { + self.checkedIndexPath = nil; + + } else { + + UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath]; + cell.accessoryType = UITableViewCellAccessoryCheckmark; + self.checkedIndexPath = indexPath; + } + // pass data back to first array + self.category.selection = [self.category.options objectAtIndex:indexPath.row]; +} + +@end diff --git a/OptionSelector.xcodeproj/project.pbxproj b/OptionSelector.xcodeproj/project.pbxproj index 1788504..c3dfcbc 100644 --- a/OptionSelector.xcodeproj/project.pbxproj +++ b/OptionSelector.xcodeproj/project.pbxproj @@ -9,11 +9,13 @@ /* Begin PBXBuildFile section */ 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 */; }; 8DECE7AC1B78082B0064D760 /* OptionSelectorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DECE7AB1B78082B0064D760 /* OptionSelectorTests.m */; }; + A4E233DD1B7ADC98009C1E3E /* CQCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = A4E233DC1B7ADC98009C1E3E /* CQCategory.m */; }; + A4E7964E1BA4C81800B6BE84 /* RootTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A4E7964D1BA4C81800B6BE84 /* RootTableViewController.m */; }; + A4E796511BA4C89C00B6BE84 /* DetailTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A4E796501BA4C89C00B6BE84 /* DetailTableViewController.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -32,14 +34,19 @@ 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 = ""; }; 8DECE7A51B78082B0064D760 /* OptionSelectorTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OptionSelectorTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 8DECE7AA1B78082B0064D760 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 8DECE7AB1B78082B0064D760 /* OptionSelectorTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OptionSelectorTests.m; sourceTree = ""; }; + A4E233DB1B7ADC98009C1E3E /* CQCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CQCategory.h; sourceTree = ""; }; + A4E233DC1B7ADC98009C1E3E /* CQCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CQCategory.m; sourceTree = ""; }; + A4E7964C1BA4C81800B6BE84 /* RootTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RootTableViewController.h; path = ../RootTableViewController.h; sourceTree = ""; }; + A4E7964D1BA4C81800B6BE84 /* RootTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RootTableViewController.m; path = ../RootTableViewController.m; sourceTree = ""; }; + A4E7964F1BA4C89C00B6BE84 /* DetailTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetailTableViewController.h; path = ../DetailTableViewController.h; sourceTree = ""; }; + A4E796501BA4C89C00B6BE84 /* DetailTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DetailTableViewController.m; path = ../DetailTableViewController.m; sourceTree = ""; }; + A4E796521BA5DA4B00B6BE84 /* DetailViewControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetailViewControllerDelegate.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -83,9 +90,14 @@ children = ( 8DECE7931B78082B0064D760 /* AppDelegate.h */, 8DECE7941B78082B0064D760 /* AppDelegate.m */, - 8DECE7961B78082B0064D760 /* ViewController.h */, - 8DECE7971B78082B0064D760 /* ViewController.m */, + A4E233DB1B7ADC98009C1E3E /* CQCategory.h */, + A4E233DC1B7ADC98009C1E3E /* CQCategory.m */, + A4E7964C1BA4C81800B6BE84 /* RootTableViewController.h */, + A4E7964D1BA4C81800B6BE84 /* RootTableViewController.m */, + A4E7964F1BA4C89C00B6BE84 /* DetailTableViewController.h */, + A4E796501BA4C89C00B6BE84 /* DetailTableViewController.m */, 8DECE7991B78082B0064D760 /* Main.storyboard */, + A4E796521BA5DA4B00B6BE84 /* DetailViewControllerDelegate.h */, 8DECE79C1B78082B0064D760 /* Images.xcassets */, 8DECE79E1B78082B0064D760 /* LaunchScreen.xib */, 8DECE78F1B78082B0064D760 /* Supporting Files */, @@ -219,9 +231,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8DECE7981B78082B0064D760 /* ViewController.m in Sources */, + A4E796511BA4C89C00B6BE84 /* DetailTableViewController.m in Sources */, 8DECE7951B78082B0064D760 /* AppDelegate.m in Sources */, + A4E233DD1B7ADC98009C1E3E /* CQCategory.m in Sources */, 8DECE7921B78082B0064D760 /* main.m in Sources */, + A4E7964E1BA4C81800B6BE84 /* RootTableViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -418,6 +432,7 @@ 8DECE7B11B78082B0064D760 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 8DECE7B21B78082B0064D760 /* Build configuration list for PBXNativeTarget "OptionSelectorTests" */ = { isa = XCConfigurationList; @@ -426,6 +441,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..2a4efdb 100644 --- a/OptionSelector/Base.lproj/Main.storyboard +++ b/OptionSelector/Base.lproj/Main.storyboard @@ -1,25 +1,87 @@ - + - + + - - + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OptionSelector/CQCategory.h b/OptionSelector/CQCategory.h new file mode 100644 index 0000000..c687685 --- /dev/null +++ b/OptionSelector/CQCategory.h @@ -0,0 +1,22 @@ +// +// CQCategory.h +// OptionSelector +// +// Created by Kaisha Jones on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface CQCategory : NSObject // this is the class name "CQCategory" + + +@property (nonatomic) NSString *name; // set public property +@property (nonatomic) NSArray *options; +@property (nonatomic) NSString *selection; + +- (instancetype)initWithCategoryType:(NSString *)type; + +//-(void) initializeData; + +@end diff --git a/OptionSelector/CQCategory.m b/OptionSelector/CQCategory.m new file mode 100644 index 0000000..e351f5f --- /dev/null +++ b/OptionSelector/CQCategory.m @@ -0,0 +1,71 @@ +// +// CQCategory.m +// OptionSelector +// +// Created by Kaisha Jones on 8/11/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "CQCategory.h" + +@implementation CQCategory + + +- (instancetype)initWithCategoryType:(NSString *)type { + self = [super init]; + if (self) { + if ([type isEqualToString:@"Happy"]) { + self.name = @"Happy"; + self.options = @[ + @"Joy", + @"Blessed", + @"Bliss", + @"Excited", + @"Optimististic", + @"Hope", + @"Delight", + @"Proud", + @"Confident" + ]; + self.selection = @""; + } else if ([type isEqualToString:@"Sad"]) { + self.name = @"Sad"; // set properties + self.options = @[ + @"Empty", + @"Hopeless", + @"Depressed", + @"Devastated", + @"Shame", + @"Guilt", + @"Anguish", + @"Pain", + @"Neglect", + @"Abandoned", + @"Torment" + ]; + self.selection = @""; + + } else if ([type isEqualToString:@"Angry"]) { + self.name = @"Angry"; + self.options = @[ + @"Rage", + @"Furry", + @"Annoyed", + @"Irritated", + @"Disgust", + @"Pissed", + @"Aggravated", + @"Mad", + @"Grumpy" + ]; + self.selection = @""; + } + } + return self; +} + + + + + +@end diff --git a/OptionSelector/DetailTableViewControllerDelegate.h b/OptionSelector/DetailTableViewControllerDelegate.h new file mode 100644 index 0000000..7ec8ab0 --- /dev/null +++ b/OptionSelector/DetailTableViewControllerDelegate.h @@ -0,0 +1,13 @@ +// +// DetailTableViewControllerDelegate.h +// OptionSelector +// +// Created by Kaisha Jones on 9/13/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import + +@protocol DetailTableViewControllerDelegate + +@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/RootTableViewController.h b/RootTableViewController.h new file mode 100644 index 0000000..cef6879 --- /dev/null +++ b/RootTableViewController.h @@ -0,0 +1,13 @@ +// +// RootTableViewController.h +// OptionSelector +// +// Created by Kaisha Jones on 9/12/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface RootTableViewController : UITableViewController + +@end diff --git a/RootTableViewController.m b/RootTableViewController.m new file mode 100644 index 0000000..373090a --- /dev/null +++ b/RootTableViewController.m @@ -0,0 +1,94 @@ +// +// RootTableViewController.m +// OptionSelector +// +// Created by Kaisha Jones on 9/12/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import "RootTableViewController.h" +#import "CQCategory.h" +#import "DetailTableViewController.h" + +@interface RootTableViewController () + +@property (nonatomic) NSArray *categories; // for entire array of category data +@property (nonatomic) NSInteger itemChosen; + + +@end + +@implementation RootTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + + self.title = @"My Emotions!!"; // this is my title + + CQCategory *happyCategory = [[CQCategory alloc] initWithCategoryType:@"Happy"]; + CQCategory *sadCategory = [[CQCategory alloc] initWithCategoryType:@"Sad"]; + CQCategory *angryCategory = [[CQCategory alloc] initWithCategoryType:@"Angry"]; + + self.categories = @[happyCategory, sadCategory, angryCategory]; + +} + + + +// reload screen with new data +- (void) viewWillAppear:(BOOL)animated { + [self.tableView reloadData]; // this reloads table view + [super viewWillAppear:animated]; // added +} + + +// set number of sections +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + + +// set number of rows in each section +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.categories.count; // rows = number of items in my array +} + + +// populate table view cell(s), add reusablecellidentifier to main.storyboard/rootVC/cell +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RootTableViewIdentifier" forIndexPath:indexPath]; + + + CQCategory *thisCategory = [self.categories objectAtIndex:indexPath.row]; // create CQCategory instance that = the general categories, the indexes and each individual row + + cell.textLabel.text = thisCategory.name; // set text label on each cell to "thisCategory" (each individual row) + + if (thisCategory.selection.length == 0) { // this forces the cell to show the right label the first time... + cell.detailTextLabel.text = @" "; + }else { + cell.detailTextLabel.text = thisCategory.selection; // this adds selection info to main table view + } + + return cell; // return the contents of each cell +} + +// segue to next table view controller +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + DetailTableViewController *detailTableViewController = segue.destinationViewController; + + // don't forget to set "" in the main storyboard + if ([segue.identifier isEqualToString:@"rootToDetailView"]) { + + NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; // index path in table view is selected + + CQCategory *selectedCategory = [self.categories objectAtIndex:indexPath.row]; // give me corresponding category + + detailTableViewController.category = selectedCategory; // detailtableview to display category contents that were selected + + } +} + + +@end +