diff --git a/Pods/AFNetworking/AFNetworking/AFURLResponseSerialization.m b/Pods/AFNetworking/AFNetworking/AFURLResponseSerialization.m index ef5e334..594a310 100755 --- a/Pods/AFNetworking/AFNetworking/AFURLResponseSerialization.m +++ b/Pods/AFNetworking/AFNetworking/AFURLResponseSerialization.m @@ -223,7 +223,7 @@ - (instancetype)init { return nil; } - self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil]; + self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"application/javascript", nil]; return self; } diff --git a/README.md b/README.md index 22c3c7e..bbe253f 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,57 @@ #Unit 3 Final App Assessment -**Topics covered** - -* Autolayout / Custom UI -* `IBAction` / Storyboard segue -* `UITableView` / `UITableViewController` / `UITableViewCell` -* Cats -* Networking -* Parsing JSON -* Passing data b/w view controllers -* `UINavigationController` -* `NSUserDefaults` -* Protocols / Delegation +This part of the assessment contains 5 screens + +**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** +This screen contains three buttons: red, green, and blue. + +*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. + + ** 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** +This screen is nothing more than a `UITableViewController`. + +*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. + +*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** diff --git a/unit-3-final-app-assessment.xcodeproj/project.pbxproj b/unit-3-final-app-assessment.xcodeproj/project.pbxproj index efe1f60..c98186c 100644 --- a/unit-3-final-app-assessment.xcodeproj/project.pbxproj +++ b/unit-3-final-app-assessment.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 5F367E5A1C25F338000A4C43 /* CustomCatTVCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F367E581C25F338000A4C43 /* CustomCatTVCell.m */; }; + 5F367E5B1C25F338000A4C43 /* CustomCatTVCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5F367E591C25F338000A4C43 /* CustomCatTVCell.xib */; }; + 5F367E5E1C271457000A4C43 /* CatSavedFactsTVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F367E5D1C271457000A4C43 /* CatSavedFactsTVC.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 +26,12 @@ /* 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 = ""; }; + 5F367E561C25D021000A4C43 /* ColorPickerCommunicationProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorPickerCommunicationProtocol.h; sourceTree = ""; }; + 5F367E571C25F338000A4C43 /* CustomCatTVCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomCatTVCell.h; sourceTree = ""; }; + 5F367E581C25F338000A4C43 /* CustomCatTVCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomCatTVCell.m; sourceTree = ""; }; + 5F367E591C25F338000A4C43 /* CustomCatTVCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CustomCatTVCell.xib; sourceTree = ""; }; + 5F367E5C1C271457000A4C43 /* CatSavedFactsTVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CatSavedFactsTVC.h; sourceTree = ""; }; + 5F367E5D1C271457000A4C43 /* CatSavedFactsTVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CatSavedFactsTVC.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 = ""; }; @@ -96,14 +105,20 @@ children = ( 8D8753061C24774700BBD328 /* AppDelegate.h */, 8D8753071C24774700BBD328 /* AppDelegate.m */, + 5F367E561C25D021000A4C43 /* ColorPickerCommunicationProtocol.h */, 8D610E9C1C2477EB00AADDC2 /* C4QViewController.h */, 8D610E9D1C2477EB00AADDC2 /* C4QViewController.m */, 8D610E961C2477EB00AADDC2 /* C4QColorPickerViewController.h */, 8D610E971C2477EB00AADDC2 /* C4QColorPickerViewController.m */, 8D610E941C2477EB00AADDC2 /* C4QCatFactsTableViewController.h */, 8D610E951C2477EB00AADDC2 /* C4QCatFactsTableViewController.m */, + 5F367E5C1C271457000A4C43 /* CatSavedFactsTVC.h */, + 5F367E5D1C271457000A4C43 /* CatSavedFactsTVC.m */, 8DA03F721C2499F400328B53 /* C4QCatFactsDetailViewController.h */, 8DA03F731C2499F400328B53 /* C4QCatFactsDetailViewController.m */, + 5F367E571C25F338000A4C43 /* CustomCatTVCell.h */, + 5F367E581C25F338000A4C43 /* CustomCatTVCell.m */, + 5F367E591C25F338000A4C43 /* CustomCatTVCell.xib */, 8D87530C1C24774700BBD328 /* Main.storyboard */, 8D87530F1C24774800BBD328 /* Assets.xcassets */, 8D8753031C24774700BBD328 /* Supporting Files */, @@ -184,6 +199,7 @@ buildActionMask = 2147483647; files = ( 8D8753131C24774800BBD328 /* LaunchScreen.storyboard in Resources */, + 5F367E5B1C25F338000A4C43 /* CustomCatTVCell.xib in Resources */, 8D8753101C24774800BBD328 /* Assets.xcassets in Resources */, 8D87530E1C24774700BBD328 /* Main.storyboard in Resources */, ); @@ -245,7 +261,9 @@ buildActionMask = 2147483647; files = ( 8D8753081C24774700BBD328 /* AppDelegate.m in Sources */, + 5F367E5A1C25F338000A4C43 /* CustomCatTVCell.m in Sources */, 8D610EA01C2477EB00AADDC2 /* C4QCatFactsTableViewController.m in Sources */, + 5F367E5E1C271457000A4C43 /* CatSavedFactsTVC.m in Sources */, 8D8753051C24774700BBD328 /* main.m in Sources */, 8DA03F741C2499F400328B53 /* C4QCatFactsDetailViewController.m in Sources */, 8D610EA41C2477EB00AADDC2 /* C4QViewController.m in Sources */, @@ -312,7 +330,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.2; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -349,7 +367,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.2; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; diff --git a/unit-3-final-app-assessment/Base.lproj/Main.storyboard b/unit-3-final-app-assessment/Base.lproj/Main.storyboard index c9e6ac4..b396e7d 100644 --- a/unit-3-final-app-assessment/Base.lproj/Main.storyboard +++ b/unit-3-final-app-assessment/Base.lproj/Main.storyboard @@ -1,8 +1,9 @@ - + - + + @@ -79,23 +80,48 @@ - - - + + + + + + + + + + + + + + + + @@ -107,43 +133,162 @@ - - + + - - + + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + diff --git a/unit-3-final-app-assessment/C4QCatFactsDetailViewController.h b/unit-3-final-app-assessment/C4QCatFactsDetailViewController.h index c4331c6..ab3f6b3 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 *catStringPassed; + @end diff --git a/unit-3-final-app-assessment/C4QCatFactsDetailViewController.m b/unit-3-final-app-assessment/C4QCatFactsDetailViewController.m index 266c9d5..5e9c704 100644 --- a/unit-3-final-app-assessment/C4QCatFactsDetailViewController.m +++ b/unit-3-final-app-assessment/C4QCatFactsDetailViewController.m @@ -7,10 +7,14 @@ // #import "C4QCatFactsDetailViewController.h" +#import -#define CAT_GIF_URL @"http://api.giphy.com/v1/gifs/search?q=funny+cat&api_key=dc6zaTOxFJmzC"; +#define CAT_GIF_URL @"http://api.giphy.com/v1/gifs/search?q=funny+cat&api_key=dc6zaTOxFJmzC" @interface C4QCatFactsDetailViewController () +@property (weak, nonatomic) IBOutlet UILabel *catLabel; +@property (weak, nonatomic) IBOutlet UIImageView *catImageView; +@property (nonatomic) NSString *catUrlString; @end @@ -19,21 +23,49 @@ @implementation C4QCatFactsDetailViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. + + self.catLabel.text = self.catStringPassed; + self.catImageView.clipsToBounds = YES; + + + //API CALL + 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 *posts = [responseObject objectForKey:@"data"]; + NSLog(@"%@", responseObject); + + int random = arc4random()%[posts count]; + + NSDictionary *randomPost = [posts objectAtIndex:random]; + + NSLog(@"%@", randomPost); + + + NSDictionary *images = [randomPost objectForKey:@"images"]; + + NSLog(@"%@", images); + NSDictionary *originalStill = [images objectForKey:@"original_still"]; + + NSLog(@"%@", originalStill); + self.catUrlString = [originalStill objectForKey:@"url"]; + + NSLog(@"%@", self.catUrlString); + + NSURL *imageURL = [NSURL URLWithString:self.catUrlString]; + NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; + self.catImageView.image = [UIImage imageWithData:imageData]; + + + + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + + NSLog(@"%@", error.userInfo); + + }]; + + + } -- (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/unit-3-final-app-assessment/C4QCatFactsTableViewController.h b/unit-3-final-app-assessment/C4QCatFactsTableViewController.h index e74c326..6ef56bd 100644 --- a/unit-3-final-app-assessment/C4QCatFactsTableViewController.h +++ b/unit-3-final-app-assessment/C4QCatFactsTableViewController.h @@ -7,7 +7,11 @@ // #import +#import "ColorPickerCommunicationProtocol.h" + @interface C4QCatFactsTableViewController : UITableViewController +@property (nonatomic, weak) id delegate; + @end diff --git a/unit-3-final-app-assessment/C4QCatFactsTableViewController.m b/unit-3-final-app-assessment/C4QCatFactsTableViewController.m index 7ad038d..ad14da5 100644 --- a/unit-3-final-app-assessment/C4QCatFactsTableViewController.m +++ b/unit-3-final-app-assessment/C4QCatFactsTableViewController.m @@ -7,10 +7,20 @@ // #import "C4QCatFactsTableViewController.h" +#import +#import "CustomCatTVCell.h" +#import "C4QCatFactsDetailViewController.h" #define CAT_API_URL @"http://catfacts-api.appspot.com/api/facts?number=100" -@interface C4QCatFactsTableViewController () +@interface C4QCatFactsTableViewController () + +@property(nonatomic)NSArray *catLadyArray; + +//@property(nonatomic)NSMutableArray *catLadyMutableArray; + +@property (strong, nonatomic) IBOutlet UITableView *catFactsTableView; @end @@ -19,6 +29,33 @@ @implementation C4QCatFactsTableViewController - (void)viewDidLoad { [super viewDidLoad]; + + + //API CALL + AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; + [manager GET:@"http://catfacts-api.appspot.com/api/facts?number=100" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + + self.catLadyArray = [responseObject objectForKey:@"facts"]; + NSLog(@"%@", responseObject); + + [self.tableView reloadData]; + + + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + + NSLog(@"%@", error.userInfo); + + }]; + + +} + + +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + self.tableView.estimatedRowHeight = 40.0; // for example. Set your average height + self.tableView.rowHeight = UITableViewAutomaticDimension; + } @@ -26,22 +63,54 @@ - (void)viewDidLoad - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 0; + return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 0; + return self.catLadyArray.count; } -/* + - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath + { - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"" forIndexPath:indexPath]; + + + CustomCatTVCell *catCell = [tableView dequeueReusableCellWithIdentifier:@"CatCellID"]; + [tableView registerNib:[UINib nibWithNibName:@"CustomCatTVCell" bundle:nil] forCellReuseIdentifier:@"CatCellID"]; + catCell = [tableView dequeueReusableCellWithIdentifier:@"CatCellID"]; + + catCell.catFactLabel.text = [self.catLadyArray objectAtIndex:indexPath.row]; - return cell; + catCell.catFact = [self.catLadyArray objectAtIndex:indexPath.row]; + + + return catCell; +} + + +-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + C4QCatFactsDetailViewController *catDeetVC = (C4QCatFactsDetailViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"catFactDetailVC"]; + catDeetVC.catStringPassed = self.catLadyArray[indexPath.row]; + [self.navigationController pushViewController:catDeetVC animated:YES]; + } -*/ + + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + // Fetch yourText for this row from your data source.. + NSString *yourText = [self.catLadyArray objectAtIndex:indexPath.row]; + + CGSize lableWidth = CGSizeMake(320, CGFLOAT_MAX); // 300 is fixed width of label. You can change this value + CGSize requiredSize = [yourText sizeWithFont:[UIFont fontWithName:@"Times New Roman" size:19] constrainedToSize:lableWidth lineBreakMode:NSLineBreakByWordWrapping]; // You can put your desire font + + int calculatedHeight = requiredSize.height+10; + return (float)calculatedHeight; +} + @end diff --git a/unit-3-final-app-assessment/C4QColorPickerViewController.h b/unit-3-final-app-assessment/C4QColorPickerViewController.h index ba6236f..305b78f 100644 --- a/unit-3-final-app-assessment/C4QColorPickerViewController.h +++ b/unit-3-final-app-assessment/C4QColorPickerViewController.h @@ -7,7 +7,16 @@ // #import +#import "C4QViewController.h" +#import "ColorPickerCommunicationProtocol.h" + @interface C4QColorPickerViewController : UIViewController +@property (nonatomic, weak) id delegate; + @end + + + + diff --git a/unit-3-final-app-assessment/C4QColorPickerViewController.m b/unit-3-final-app-assessment/C4QColorPickerViewController.m index 23e957d..6556d65 100644 --- a/unit-3-final-app-assessment/C4QColorPickerViewController.m +++ b/unit-3-final-app-assessment/C4QColorPickerViewController.m @@ -18,6 +18,8 @@ @interface C4QColorPickerViewController () @implementation C4QColorPickerViewController + + - (void)viewDidLoad { [super viewDidLoad]; @@ -26,4 +28,35 @@ - (void)viewDidLoad { self.redButton.backgroundColor = [UIColor redColor]; } +- (IBAction)greenButtonTapped:(UIButton *)sender { + + + NSString *color = @"green"; + + [self.delegate addColor:color]; + + [self.delegate colorPicked:[UIColor greenColor]]; + + [self.navigationController popToRootViewControllerAnimated:YES]; + +} + + +- (IBAction)redButtonTapped:(UIButton *)sender { + + + [self.delegate colorPicked:[UIColor redColor]]; + + [self.navigationController popToRootViewControllerAnimated:YES]; +} + + + +- (IBAction)blueButtonTapped:(UIButton *)sender { + + [self.delegate colorPicked:[UIColor blueColor]]; + + [self.navigationController popToRootViewControllerAnimated:YES]; +} + @end diff --git a/unit-3-final-app-assessment/C4QViewController.h b/unit-3-final-app-assessment/C4QViewController.h index 0c0bdc3..8eebc66 100644 --- a/unit-3-final-app-assessment/C4QViewController.h +++ b/unit-3-final-app-assessment/C4QViewController.h @@ -9,6 +9,7 @@ #import #import "C4QRootViewController.h" + @interface C4QViewController : C4QRootViewController diff --git a/unit-3-final-app-assessment/C4QViewController.m b/unit-3-final-app-assessment/C4QViewController.m index 5d34ae3..c41bd2d 100644 --- a/unit-3-final-app-assessment/C4QViewController.m +++ b/unit-3-final-app-assessment/C4QViewController.m @@ -7,11 +7,50 @@ // #import "C4QViewController.h" +#import "ColorPickerCommunicationProtocol.h" +#import "C4QColorPickerViewController.h" +#import "C4QCatFactsTableViewController.h" +#import "C4QRootViewController.h" -@interface C4QViewController () +@interface C4QViewController () + +@property (nonatomic) NSMutableArray *colors; @end + + @implementation C4QViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.colors = [[NSMutableArray alloc] init]; + +} + +-(void)prepareForSegue:(nonnull UIStoryboardSegue *)segue sender:(nullable id)sender { + if (self.view.backgroundColor == [UIColor greenColor]) { + C4QCatFactsTableViewController *catViewController = segue.destinationViewController; + catViewController.delegate = self; + } else { + C4QColorPickerViewController *viewController = segue.destinationViewController; + viewController.delegate = self; + } + + +} + +- (void)addColor: (NSString *)colorAdded { + NSLog(@"%@", colorAdded); +} + + +- (void)colorPicked: (UIColor *)colorDisplayed { + self.view.backgroundColor = colorDisplayed; +} + + + @end diff --git a/unit-3-final-app-assessment/CatSavedFactsTVC.h b/unit-3-final-app-assessment/CatSavedFactsTVC.h new file mode 100644 index 0000000..f43e334 --- /dev/null +++ b/unit-3-final-app-assessment/CatSavedFactsTVC.h @@ -0,0 +1,13 @@ +// +// CatSavedFactsTVC.h +// unit-3-final-app-assessment +// +// Created by Zoufishan Mehdi on 12/20/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import + +@interface CatSavedFactsTVC : UITableViewController + +@end diff --git a/unit-3-final-app-assessment/CatSavedFactsTVC.m b/unit-3-final-app-assessment/CatSavedFactsTVC.m new file mode 100644 index 0000000..262e112 --- /dev/null +++ b/unit-3-final-app-assessment/CatSavedFactsTVC.m @@ -0,0 +1,68 @@ +// +// CatSavedFactsTVC.m +// unit-3-final-app-assessment +// +// Created by Zoufishan Mehdi on 12/20/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "CatSavedFactsTVC.h" + +@interface CatSavedFactsTVC () + +@property (nonatomic) NSArray* savedCatFacts; + +@end + +@implementation CatSavedFactsTVC + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.savedCatFacts = [[NSUserDefaults standardUserDefaults] objectForKey:@"savedCatFacts"]; + +} + + + +- (IBAction)doneButtonTapped:(UIBarButtonItem *)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:@"DefaultIdentifier" forIndexPath:indexPath]; + + cell.textLabel.text = [self.savedCatFacts objectAtIndex:indexPath.row]; + + return cell; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + // Fetch yourText for this row from your data source.. + NSString *yourText = [self.savedCatFacts objectAtIndex:indexPath.row]; + + CGSize lableWidth = CGSizeMake(350, CGFLOAT_MAX); // 300 is fixed width of label. You can change this value + CGSize requiredSize = [yourText sizeWithFont:[UIFont fontWithName:@"Times New Roman" size:19] constrainedToSize:lableWidth lineBreakMode:NSLineBreakByWordWrapping]; // You can put your desire font + + + int calculatedHeight = requiredSize.height+10; + return (float)calculatedHeight; +} + + + +@end diff --git a/unit-3-final-app-assessment/ColorPickerCommunicationProtocol.h b/unit-3-final-app-assessment/ColorPickerCommunicationProtocol.h new file mode 100644 index 0000000..450e7f1 --- /dev/null +++ b/unit-3-final-app-assessment/ColorPickerCommunicationProtocol.h @@ -0,0 +1,18 @@ +// +// ColorPickerCommunicationProtocol.h +// ColorPicker +// +// Created by Zoufishan Mehdi on 9/12/15. +// Copyright © 2015 Zoufishan Mehdi. All rights reserved. +// + +#import + +@protocol ColorPickerCommunicationProtocol + +@optional +- (void)addColor: (NSString *)colorAdded; + +- (void)colorPicked: (UIColor *)colorDisplayed; + +@end diff --git a/unit-3-final-app-assessment/CustomCatTVCell.h b/unit-3-final-app-assessment/CustomCatTVCell.h new file mode 100644 index 0000000..1e7aa06 --- /dev/null +++ b/unit-3-final-app-assessment/CustomCatTVCell.h @@ -0,0 +1,18 @@ +// +// CustomCatTVCell.h +// unit-3-final-app-assessment +// +// Created by Zoufishan Mehdi on 12/19/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import + +@interface CustomCatTVCell : UITableViewCell +@property (weak, nonatomic) IBOutlet UILabel *catFactLabel; +@property (nonatomic) NSString *catFact; +@property (weak, nonatomic) IBOutlet UIButton *addButton; + + + +@end diff --git a/unit-3-final-app-assessment/CustomCatTVCell.m b/unit-3-final-app-assessment/CustomCatTVCell.m new file mode 100644 index 0000000..a48a0fc --- /dev/null +++ b/unit-3-final-app-assessment/CustomCatTVCell.m @@ -0,0 +1,62 @@ +// +// CustomCatTVCell.m +// unit-3-final-app-assessment +// +// Created by Zoufishan Mehdi on 12/19/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "CustomCatTVCell.h" + +@implementation CustomCatTVCell + +- (void)awakeFromNib { + // Initialization code +} + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated { + [super setSelected:selected animated:animated]; + + // Configure the view for the selected state +} +- (IBAction)catButtonTapped:(UIButton *)sender { + + if ([[NSUserDefaults standardUserDefaults] objectForKey:@"savedCatFacts"]) { + NSArray *catFactArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"savedCatFacts"]; + NSMutableArray *catMutableCopy = [catFactArray mutableCopy]; + [catMutableCopy addObject:self.catFact]; + NSArray *catArray = [catMutableCopy copy]; + [[NSUserDefaults standardUserDefaults] setObject:catArray forKey:@"savedCatFacts"]; + + } + else{ + NSArray *catFactArray = [[NSArray alloc]initWithObjects:self.catFact, nil]; + [[NSUserDefaults standardUserDefaults] setObject:catFactArray forKey:@"savedCatFacts"]; + } + + UIAlertController * alert= [UIAlertController + alertControllerWithTitle:@"Saved" + message:@"New cat fact saved!" + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction* yesButton = [UIAlertAction + actionWithTitle:@"OK" + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) + { + [alert dismissViewControllerAnimated:YES completion:nil]; + + }]; + + [alert addAction:yesButton]; + + [self.window.rootViewController presentViewController:alert animated:YES completion:nil]; + + +} + + + + + +@end diff --git a/unit-3-final-app-assessment/CustomCatTVCell.xib b/unit-3-final-app-assessment/CustomCatTVCell.xib new file mode 100644 index 0000000..b62085b --- /dev/null +++ b/unit-3-final-app-assessment/CustomCatTVCell.xib @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +