Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lauren Caponong homework #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CQCategory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// CQCategory.h
// OptionSelector
//
// Created by Lauren Caponong on 8/11/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface CQCategory : NSObject

@property (nonatomic) NSString *name;
@property (nonatomic) NSArray *options;
@property (nonatomic) NSString *selection;

- (void)initializeData;

@end
21 changes: 21 additions & 0 deletions CQCategory.m
Original file line number Diff line number Diff line change
@@ -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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this method necessary? Since it doesn't actually affect the state of the code. :D


[self name];
[self options];
[self selection];
}


@end
32 changes: 26 additions & 6 deletions OptionSelector.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 = "<group>"; };
898EFF231B7AD61E00A30F21 /* NavigationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationViewController.m; sourceTree = "<group>"; };
898EFF251B7AD63D00A30F21 /* AnimalDetailTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnimalDetailTableViewController.h; sourceTree = "<group>"; };
898EFF261B7AD63D00A30F21 /* AnimalDetailTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnimalDetailTableViewController.m; sourceTree = "<group>"; };
898EFF281B7AD65E00A30F21 /* AnimalTypesTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnimalTypesTableViewController.h; sourceTree = "<group>"; };
898EFF291B7AD65E00A30F21 /* AnimalTypesTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnimalTypesTableViewController.m; sourceTree = "<group>"; };
898EFF2E1B7AD82F00A30F21 /* CQCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CQCategory.h; path = ../CQCategory.h; sourceTree = "<group>"; };
898EFF2F1B7AD82F00A30F21 /* CQCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CQCategory.m; path = ../CQCategory.m; sourceTree = "<group>"; };
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 = "<group>"; };
8DECE7911B78082B0064D760 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
8DECE7931B78082B0064D760 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
8DECE7941B78082B0064D760 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
8DECE7961B78082B0064D760 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
8DECE7971B78082B0064D760 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
8DECE79A1B78082B0064D760 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
8DECE79C1B78082B0064D760 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
8DECE79F1B78082B0064D760 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -418,6 +436,7 @@
8DECE7B11B78082B0064D760 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
8DECE7B21B78082B0064D760 /* Build configuration list for PBXNativeTarget "OptionSelectorTests" */ = {
isa = XCConfigurationList;
Expand All @@ -426,6 +445,7 @@
8DECE7B41B78082B0064D760 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
29 changes: 29 additions & 0 deletions OptionSelector/AnimalDetailTableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// AnimalDetailTableViewController.h
// OptionSelector
//
// Created by Lauren Caponong on 8/11/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "CQCategory.h"

@class AnimalDetailTableViewController;

@protocol ViewControllerAnimalDetailTableViewDelegate <NSObject>
- (void)addItemViewController:(AnimalDetailTableViewController *)controller didFinishEnteringItem:(CQCategory *)item;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work with the delegate protocol!

@end




@interface AnimalDetailTableViewController : UITableViewController

@property (nonatomic) CQCategory *thing;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best to use variable names that are as specific as possible. Usually names like number or myArray or thing aren't that useful, because they don't provide much context about why that variable exists and what it does.

@property (nonatomic, weak) id <ViewControllerAnimalDetailTableViewDelegate> delegate;

@property (nonatomic, retain) NSString *selectedThing;


@end
91 changes: 91 additions & 0 deletions OptionSelector/AnimalDetailTableViewController.m
Original file line number Diff line number Diff line change
@@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



@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];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does your AnimalDetailTableViewController need its own copies of each animal category? Won't it be receiving these objects from your root view controller?



}

- (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
15 changes: 15 additions & 0 deletions OptionSelector/AnimalTypesTableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// AnimalTypesTableViewController.h
// OptionSelector
//
// Created by Lauren Caponong on 8/11/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "AnimalDetailTableViewController.h"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this #import necessary?



@interface AnimalTypesTableViewController : UITableViewController

@end
Loading