From 8e5139007e69c03ed52f3be9c9e6cb287e918a9a Mon Sep 17 00:00:00 2001 From: Mike Kavouras Date: Fri, 18 Dec 2015 15:53:27 -0500 Subject: [PATCH 1/5] Update README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 22c3c7e..7873000 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,17 @@ #Unit 3 Final App Assessment +There are 5 screens in this application. Video below as well as images for each screen. + +**1st screen** + +**2nd screen** + +**3rd screen** + +**4th screen** + +**5th screen** + **Topics covered** * Autolayout / Custom UI From 8645aed1ecba03517af7547953670b3f07ef4e9d Mon Sep 17 00:00:00 2001 From: Mike Kavouras Date: Sat, 19 Dec 2015 09:35:47 -0500 Subject: [PATCH 2/5] Update README.md --- README.md | 62 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 7873000..0597316 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,57 @@ #Unit 3 Final App Assessment -There are 5 screens in this application. Video below as well as images for each screen. +This part of the assessment contains 5 screens -**1st screen** +**Screen 1** +This screen contains two buttons, one visible and one hidden. +*Requirements* +* Conform to the protocol created in screen 2 and implement all required methods. +* Segue to screen 3 (via the hidden button) -**2nd screen** +**Screen 2** +This screen contains three buttons: red, green, and blue. -**3rd screen** +*Requirements* +* Set constraints in the storyboard so that each button takes up equal space within the view (should work landscape) +* Implement a custom protocol (delegate). This protocol will have a single method for sending a single `UIColor` from screen 2 to its delegate. + Whenever the user selects a color button, the view controller will send the color (either `[UIColor redColor]`, `[UIColor greenColor]`, + or `[UIColor blueColor]`) to its delegate as a parameter. In this situation, the delegate will be screen 1. -**4th screen** + ** When the delegate (screen 1) receives a color, it should set its view's background color. When the correct color is selected the + hidden button will appear ** -**5th screen** +**Screen 3** +This screen is nothing more than a `UITableViewController`. -**Topics covered** +*Requirements* +* Populate the table with random cat facts. The API information is set for you at the top of `C4QCatFactsTableViewController.m`. +* Create a custom `UITableViewCell` with a + button on the right side (asset is already in the project). +* Save a cat fact in `NSUserDefaults` when the + button is tapped. +* The height of the cell should be variable based on the amount of text provided. -* Autolayout / Custom UI -* `IBAction` / Storyboard segue -* `UITableView` / `UITableViewController` / `UITableViewCell` -* Cats -* Networking -* Parsing JSON -* Passing data b/w view controllers -* `UINavigationController` -* `NSUserDefaults` -* Protocols / Delegation +*Bonus* +* Present an alert whenever you save a cat fact +* Change the + button to a checkmark indicating that a fact is already saved + +**Screen 4** +This is a very basic `UITableViewController`. Nothing more. + +*Requirements* +* Display the saved cat facts. + +**Screen 5** +This is a detail view for your cat facts. Tapping on a cell in screen 3 will segue to this screen. + +*Requirements* +* Display a random cat photo in full screen in the background (API information is in `C4QCatFactsDetailViewController.m`). +* Display the text that corresponds with the cell tapped. +* The text must be centered vertically and have 40pts space on the left and right. +* The background image should have a content mode of aspect fill and SHOULD NOT overflow the view (when you + go back to the previous screen you shouldn't see part of the image) + +*Bonus* +* Load the cat image on a background thread so that it doesn't freeze the UI +* If the image isn't downloaded by the time you hit the back button, cancel the download task. **Bonus** From 3a83470c2baba8856b7e84ef4643367dbd4ae2fa Mon Sep 17 00:00:00 2001 From: Mike Kavouras Date: Sat, 19 Dec 2015 09:37:30 -0500 Subject: [PATCH 3/5] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0597316..bbe253f 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ This part of the assessment contains 5 screens -**Screen 1** +**Screen 1** This screen contains two buttons, one visible and one hidden. *Requirements* * Conform to the protocol created in screen 2 and implement all required methods. * Segue to screen 3 (via the hidden button) -**Screen 2** +**Screen 2** This screen contains three buttons: red, green, and blue. *Requirements* @@ -20,7 +20,7 @@ This screen contains three buttons: red, green, and blue. ** When the delegate (screen 1) receives a color, it should set its view's background color. When the correct color is selected the hidden button will appear ** -**Screen 3** +**Screen 3** This screen is nothing more than a `UITableViewController`. *Requirements* @@ -33,7 +33,7 @@ This screen is nothing more than a `UITableViewController`. * Present an alert whenever you save a cat fact * Change the + button to a checkmark indicating that a fact is already saved -**Screen 4** +**Screen 4** This is a very basic `UITableViewController`. Nothing more. *Requirements* From 32e7119e2291bdef8fed253774092b5df15c68c2 Mon Sep 17 00:00:00 2001 From: Lauren Date: Sun, 20 Dec 2015 08:30:55 -0500 Subject: [PATCH 4/5] Finished app --- .../project.pbxproj | 14 + .../Base.lproj/Main.storyboard | 289 ++++++++++++++++-- .../C4QCatFactsDetailViewController.h | 2 + .../C4QCatFactsDetailViewController.m | 58 ++-- .../C4QCatFactsTableViewController.m | 136 ++++++++- .../C4QColorPickerViewController.h | 13 + .../C4QColorPickerViewController.m | 10 + .../C4QViewController.m | 31 +- .../CatFactTableViewCell.h | 16 + .../CatFactTableViewCell.m | 23 ++ .../SavedCatFactsTableViewController.h | 13 + .../SavedCatFactsTableViewController.m | 89 ++++++ 12 files changed, 652 insertions(+), 42 deletions(-) create mode 100644 unit-3-final-app-assessment/CatFactTableViewCell.h create mode 100644 unit-3-final-app-assessment/CatFactTableViewCell.m create mode 100644 unit-3-final-app-assessment/SavedCatFactsTableViewController.h create mode 100644 unit-3-final-app-assessment/SavedCatFactsTableViewController.m diff --git a/unit-3-final-app-assessment.xcodeproj/project.pbxproj b/unit-3-final-app-assessment.xcodeproj/project.pbxproj index efe1f60..1bcce37 100644 --- a/unit-3-final-app-assessment.xcodeproj/project.pbxproj +++ b/unit-3-final-app-assessment.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 89B7F1531C260E6200B45596 /* SavedCatFactsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 89B7F1521C260E6200B45596 /* SavedCatFactsTableViewController.m */; }; + 89B7F1571C2617F400B45596 /* CatFactTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 89B7F1561C2617F400B45596 /* CatFactTableViewCell.m */; }; 8D610EA01C2477EB00AADDC2 /* C4QCatFactsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D610E951C2477EB00AADDC2 /* C4QCatFactsTableViewController.m */; }; 8D610EA11C2477EB00AADDC2 /* C4QColorPickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D610E971C2477EB00AADDC2 /* C4QColorPickerViewController.m */; }; 8D610EA21C2477EB00AADDC2 /* C4QRootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D610E991C2477EB00AADDC2 /* C4QRootViewController.m */; }; @@ -23,6 +25,10 @@ /* Begin PBXFileReference section */ 4292FCC8B28330B5275CBFBD /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; 4298908874A5133FD8BE086A /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; + 89B7F1511C260E6200B45596 /* SavedCatFactsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SavedCatFactsTableViewController.h; sourceTree = ""; }; + 89B7F1521C260E6200B45596 /* SavedCatFactsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SavedCatFactsTableViewController.m; sourceTree = ""; }; + 89B7F1551C2617F400B45596 /* CatFactTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CatFactTableViewCell.h; sourceTree = ""; }; + 89B7F1561C2617F400B45596 /* CatFactTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CatFactTableViewCell.m; sourceTree = ""; }; 8D610E941C2477EB00AADDC2 /* C4QCatFactsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = C4QCatFactsTableViewController.h; sourceTree = ""; }; 8D610E951C2477EB00AADDC2 /* C4QCatFactsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = C4QCatFactsTableViewController.m; sourceTree = ""; }; 8D610E961C2477EB00AADDC2 /* C4QColorPickerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = C4QColorPickerViewController.h; sourceTree = ""; }; @@ -102,8 +108,12 @@ 8D610E971C2477EB00AADDC2 /* C4QColorPickerViewController.m */, 8D610E941C2477EB00AADDC2 /* C4QCatFactsTableViewController.h */, 8D610E951C2477EB00AADDC2 /* C4QCatFactsTableViewController.m */, + 89B7F1511C260E6200B45596 /* SavedCatFactsTableViewController.h */, + 89B7F1521C260E6200B45596 /* SavedCatFactsTableViewController.m */, 8DA03F721C2499F400328B53 /* C4QCatFactsDetailViewController.h */, 8DA03F731C2499F400328B53 /* C4QCatFactsDetailViewController.m */, + 89B7F1551C2617F400B45596 /* CatFactTableViewCell.h */, + 89B7F1561C2617F400B45596 /* CatFactTableViewCell.m */, 8D87530C1C24774700BBD328 /* Main.storyboard */, 8D87530F1C24774800BBD328 /* Assets.xcassets */, 8D8753031C24774700BBD328 /* Supporting Files */, @@ -244,12 +254,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 89B7F1571C2617F400B45596 /* CatFactTableViewCell.m in Sources */, 8D8753081C24774700BBD328 /* AppDelegate.m in Sources */, 8D610EA01C2477EB00AADDC2 /* C4QCatFactsTableViewController.m in Sources */, 8D8753051C24774700BBD328 /* main.m in Sources */, 8DA03F741C2499F400328B53 /* C4QCatFactsDetailViewController.m in Sources */, 8D610EA41C2477EB00AADDC2 /* C4QViewController.m in Sources */, 8D610EA11C2477EB00AADDC2 /* C4QColorPickerViewController.m in Sources */, + 89B7F1531C260E6200B45596 /* SavedCatFactsTableViewController.m in Sources */, 8D610EA21C2477EB00AADDC2 /* C4QRootViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -363,6 +375,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = "unit-3-final-app-assessment/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.mikekavouras.unit-3-final-app-assessment"; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -375,6 +388,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = "unit-3-final-app-assessment/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.mikekavouras.unit-3-final-app-assessment"; PRODUCT_NAME = "$(TARGET_NAME)"; }; diff --git a/unit-3-final-app-assessment/Base.lproj/Main.storyboard b/unit-3-final-app-assessment/Base.lproj/Main.storyboard index c9e6ac4..8ae18aa 100644 --- a/unit-3-final-app-assessment/Base.lproj/Main.storyboard +++ b/unit-3-final-app-assessment/Base.lproj/Main.storyboard @@ -3,6 +3,8 @@ + + @@ -34,14 +36,21 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -111,27 +322,57 @@ - + - - + + - + - + + + + + + + + + + + + + + + + + + + + @@ -139,11 +380,23 @@ - + + + + + + + - + + + + + + + diff --git a/unit-3-final-app-assessment/C4QCatFactsDetailViewController.h b/unit-3-final-app-assessment/C4QCatFactsDetailViewController.h index c4331c6..c4af229 100644 --- a/unit-3-final-app-assessment/C4QCatFactsDetailViewController.h +++ b/unit-3-final-app-assessment/C4QCatFactsDetailViewController.h @@ -10,4 +10,6 @@ @interface C4QCatFactsDetailViewController : UIViewController +@property (nonatomic) NSString *catFact; + @end diff --git a/unit-3-final-app-assessment/C4QCatFactsDetailViewController.m b/unit-3-final-app-assessment/C4QCatFactsDetailViewController.m index 266c9d5..ab3a987 100644 --- a/unit-3-final-app-assessment/C4QCatFactsDetailViewController.m +++ b/unit-3-final-app-assessment/C4QCatFactsDetailViewController.m @@ -7,33 +7,57 @@ // #import "C4QCatFactsDetailViewController.h" +#import #define CAT_GIF_URL @"http://api.giphy.com/v1/gifs/search?q=funny+cat&api_key=dc6zaTOxFJmzC"; @interface C4QCatFactsDetailViewController () +@property (weak, nonatomic) IBOutlet UILabel *catFactDetailLabel; +@property (weak, nonatomic) IBOutlet UIImageView *imageBackground; + @end -@implementation C4QCatFactsDetailViewController -- (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 +@implementation C4QCatFactsDetailViewController -// 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. +- (void)viewDidLoad { + [super viewDidLoad]; + + self.catFactDetailLabel.text = self.catFact; + + AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; + + [manager GET:@"http://api.giphy.com/v1/gifs/search?q=funny+cat&api_key=dc6zaTOxFJmzC" + parameters:nil + progress:nil + success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + + NSArray *data = responseObject [@"data"]; + + int random = (arc4random() % data.count) + 1; + + NSString *imageURLString = data[random][@"images"][@"fixed_height_still"][@"url"]; + + NSURL *url = [NSURL URLWithString:imageURLString]; + + NSData *imageData = [NSData dataWithContentsOfURL:url]; + + UIImage *image = [UIImage imageWithData:imageData]; + + [self.imageBackground setImage:image]; + + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + + NSLog(@"Error: %@", error); + + }]; + + + + self.imageBackground.clipsToBounds = YES; + } -*/ - @end diff --git a/unit-3-final-app-assessment/C4QCatFactsTableViewController.m b/unit-3-final-app-assessment/C4QCatFactsTableViewController.m index 7fc7a04..a32a319 100644 --- a/unit-3-final-app-assessment/C4QCatFactsTableViewController.m +++ b/unit-3-final-app-assessment/C4QCatFactsTableViewController.m @@ -7,11 +7,16 @@ // #import "C4QCatFactsTableViewController.h" +#import +#import "CatFactTableViewCell.h" +#import "C4QCatFactsDetailViewController.h" #define CAT_API_URL @"http://catfacts-api.appspot.com/api/facts?number=100" @interface C4QCatFactsTableViewController () +@property (nonatomic) NSMutableArray *catFacts; + @end @implementation C4QCatFactsTableViewController @@ -19,29 +24,148 @@ @implementation C4QCatFactsTableViewController - (void)viewDidLoad { [super viewDidLoad]; + + [self fetchCatFacts]; } +- (void) fetchCatFacts { + + + + NSString *urlString = @"http://catfacts-api.appspot.com/api/facts?number=100"; + + + AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; + + AFJSONResponseSerializer *jsonReponseSerializer = [AFJSONResponseSerializer serializer]; + + jsonReponseSerializer.acceptableContentTypes = nil; + + manager.responseSerializer = jsonReponseSerializer; + + [manager GET:CAT_API_URL parameters:nil + progress:nil + success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + + NSLog(@"JSON ==== %@",responseObject); + + if (responseObject[@"success"]) { + + self.catFacts = [[NSArray alloc]initWithArray:responseObject[@"facts"]]; + + [self.tableView reloadData]; + + } else { + + NSLog(@"Error"); + } + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSLog(@"Error ==== %@",error); + }]; + + + +} + + + +- (IBAction)plusButtonTapped:(UIButton *)sender { + + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Cat Facts" + message:@"Fact saved" + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Great" + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * _Nonnull action) { + + if (![[NSUserDefaults standardUserDefaults] objectForKey:@"savedCatFactsArray"]) { + + NSMutableArray *savedCatFactsArray = [[NSMutableArray alloc] init]; + + [savedCatFactsArray addObject:self.catFacts[sender.tag]]; + + [[NSUserDefaults standardUserDefaults] setObject:savedCatFactsArray forKey:@"savedCatFactsArray"]; + + } else { + NSMutableArray *savedCatFactsArray2 = [[NSMutableArray alloc] + initWithArray:[[[NSUserDefaults standardUserDefaults] + objectForKey:@"savedCatFactsArray"] mutableCopy]]; + + [savedCatFactsArray2 addObject:self.catFacts[sender.tag]]; + + [[NSUserDefaults standardUserDefaults] setObject:savedCatFactsArray2 forKey:@"savedCatFactsArray"]; + } + + }]; + + + [alert addAction:okAction]; + + [self presentViewController:alert animated:YES completion:nil]; + + +} + + + + #pragma mark - Table view data source + - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 0; + return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 0; + return self.catFacts.count; } -/* -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath + + + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CatFactIdentifier" forIndexPath:indexPath]; + + NSString *str = [self.catFacts objectAtIndex:indexPath.row]; + + CGSize size = [str sizeWithFont:[UIFont fontWithName:@"Helvetica" size:17] constrainedToSize:CGSizeMake(280, 999) lineBreakMode:NSLineBreakByWordWrapping]; + + return size.height + 20; + +} + + +- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + + CatFactTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CatFactIdentifier" forIndexPath:indexPath]; + + cell.catFactLabel.text = self.catFacts[indexPath.row]; + + cell.plusButton.tag = indexPath.row; return cell; + + } -*/ + + +-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ + + NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; + + if ([segue.identifier isEqualToString:@"catDetailSegue"]) { + + C4QCatFactsDetailViewController *vc = segue.destinationViewController; + + vc.catFact = self.catFacts[indexPath.row]; + } +} + + @end diff --git a/unit-3-final-app-assessment/C4QColorPickerViewController.h b/unit-3-final-app-assessment/C4QColorPickerViewController.h index ba6236f..0481af0 100644 --- a/unit-3-final-app-assessment/C4QColorPickerViewController.h +++ b/unit-3-final-app-assessment/C4QColorPickerViewController.h @@ -8,6 +8,19 @@ #import + +@protocol colorPassingDelegate + +- (void) userDidSelectColor:(UIColor *) color; + +@end + + + + + @interface C4QColorPickerViewController : UIViewController +@property (weak, nonatomic) id delegate; + @end diff --git a/unit-3-final-app-assessment/C4QColorPickerViewController.m b/unit-3-final-app-assessment/C4QColorPickerViewController.m index 23e957d..42d779f 100644 --- a/unit-3-final-app-assessment/C4QColorPickerViewController.m +++ b/unit-3-final-app-assessment/C4QColorPickerViewController.m @@ -26,4 +26,14 @@ - (void)viewDidLoad { self.redButton.backgroundColor = [UIColor redColor]; } + +- (IBAction)colorTapped:(UIButton *)sender { + + [self.delegate userDidSelectColor:sender.backgroundColor]; + + [self.navigationController popViewControllerAnimated:YES]; +} + + + @end diff --git a/unit-3-final-app-assessment/C4QViewController.m b/unit-3-final-app-assessment/C4QViewController.m index 5d34ae3..c06ecee 100644 --- a/unit-3-final-app-assessment/C4QViewController.m +++ b/unit-3-final-app-assessment/C4QViewController.m @@ -7,11 +7,40 @@ // #import "C4QViewController.h" +#import "C4QColorPickerViewController.h" +#import "C4QCatFactsTableViewController.h" -@interface C4QViewController () +@interface C4QViewController () @end @implementation C4QViewController + + +- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + + + if ([segue.identifier isEqualToString:@"colorsSegue"]) { + + C4QColorPickerViewController *svc = segue.destinationViewController; + svc.delegate = self; + + } else { + + } + +} + + +- (void) userDidSelectColor:(UIColor *)color { + + self.view.backgroundColor = color; + + +} + + + + @end diff --git a/unit-3-final-app-assessment/CatFactTableViewCell.h b/unit-3-final-app-assessment/CatFactTableViewCell.h new file mode 100644 index 0000000..ffa8151 --- /dev/null +++ b/unit-3-final-app-assessment/CatFactTableViewCell.h @@ -0,0 +1,16 @@ +// +// CatFactTableViewCell.h +// unit-3-final-app-assessment +// +// Created by Lauren Caponong on 12/19/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import + +@interface CatFactTableViewCell : UITableViewCell + +@property (weak, nonatomic) IBOutlet UILabel *catFactLabel; +@property (weak, nonatomic) IBOutlet UIButton *plusButton; + +@end diff --git a/unit-3-final-app-assessment/CatFactTableViewCell.m b/unit-3-final-app-assessment/CatFactTableViewCell.m new file mode 100644 index 0000000..bc63905 --- /dev/null +++ b/unit-3-final-app-assessment/CatFactTableViewCell.m @@ -0,0 +1,23 @@ +// +// CatFactTableViewCell.m +// unit-3-final-app-assessment +// +// Created by Lauren Caponong on 12/19/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "CatFactTableViewCell.h" + +@implementation CatFactTableViewCell + +- (void)awakeFromNib { + // Initialization code +} + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated { + [super setSelected:selected animated:animated]; + + // Configure the view for the selected state +} + +@end diff --git a/unit-3-final-app-assessment/SavedCatFactsTableViewController.h b/unit-3-final-app-assessment/SavedCatFactsTableViewController.h new file mode 100644 index 0000000..1989ce7 --- /dev/null +++ b/unit-3-final-app-assessment/SavedCatFactsTableViewController.h @@ -0,0 +1,13 @@ +// +// SavedCatFactsTableViewController.h +// unit-3-final-app-assessment +// +// Created by Lauren Caponong on 12/19/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import + +@interface SavedCatFactsTableViewController : UITableViewController + +@end diff --git a/unit-3-final-app-assessment/SavedCatFactsTableViewController.m b/unit-3-final-app-assessment/SavedCatFactsTableViewController.m new file mode 100644 index 0000000..122d330 --- /dev/null +++ b/unit-3-final-app-assessment/SavedCatFactsTableViewController.m @@ -0,0 +1,89 @@ +// +// SavedCatFactsTableViewController.m +// unit-3-final-app-assessment +// +// Created by Lauren Caponong on 12/19/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "SavedCatFactsTableViewController.h" +#import "C4QCatFactsDetailViewController.h" + +@interface SavedCatFactsTableViewController () + +@property (nonatomic) NSMutableArray *savedCatFacts; + +@end + + +@implementation SavedCatFactsTableViewController + +- (void)viewDidLoad { + + [super viewDidLoad]; + + self.navigationItem.title = @"Your Saved Cat Facts"; + + self.savedCatFacts = [[NSMutableArray alloc] init]; + + self.savedCatFacts = [[NSUserDefaults standardUserDefaults] objectForKey:@"savedCatFactsArray"]; + +} + +- (IBAction)doneTapped:(id)sender { + + [self dismissViewControllerAnimated:YES completion:nil]; + +} + + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + + return self.savedCatFacts.count; +} + + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SavedFactsIdentifier" forIndexPath:indexPath]; + + cell.textLabel.text = self.savedCatFacts[indexPath.row]; + + return cell; + + } + + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + + NSString *str = [self.savedCatFacts objectAtIndex:indexPath.row]; + + CGSize size = [str sizeWithFont:[UIFont fontWithName:@"Helvetica" size:17] constrainedToSize:CGSizeMake(280, 999) lineBreakMode:NSLineBreakByWordWrapping]; + + return size.height + 20; + +} + + +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + + NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; + + if ([segue.identifier isEqualToString:@"SavedFactsSegue"]) { + + C4QCatFactsDetailViewController *dvc = segue.destinationViewController; + + dvc.catFact = self.savedCatFacts[indexPath.row]; + } +} + + + +@end From 50d6638f1a29473ca83ff231cf2c88a291b4c9f6 Mon Sep 17 00:00:00 2001 From: Lauren Date: Sun, 20 Dec 2015 08:44:39 -0500 Subject: [PATCH 5/5] finished --- unit-3-final-app-assessment/.gitignore | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 unit-3-final-app-assessment/.gitignore diff --git a/unit-3-final-app-assessment/.gitignore b/unit-3-final-app-assessment/.gitignore new file mode 100644 index 0000000..c964cd8 --- /dev/null +++ b/unit-3-final-app-assessment/.gitignore @@ -0,0 +1,26 @@ +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control +# +#Pods/