From c7bf4033ac4d29e0c58a43c4f06eea36f4c34c49 Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 9 Oct 2015 21:50:01 -0400 Subject: [PATCH 1/3] First commit - made tasks and can store them --- MarsWater/MarsWater.xcodeproj/project.pbxproj | 20 ++ .../MarsWater/Base.lproj/Main.storyboard | 245 +++++++++++++++++- .../ListCreationTableViewController.m | 7 + .../MarsWater/ListsTableViewController.m | 25 +- .../MarsWater.xcdatamodel/contents | 2 +- MarsWater/MarsWater/Task+CoreDataProperties.h | 1 + MarsWater/MarsWater/Task+CoreDataProperties.m | 1 + .../TaskCreationTableViewController.h | 13 + .../TaskCreationTableViewController.m | 83 ++++++ .../MarsWater/TasksTableViewController.h | 13 + .../MarsWater/TasksTableViewController.m | 82 ++++++ 11 files changed, 473 insertions(+), 19 deletions(-) create mode 100644 MarsWater/MarsWater/TaskCreationTableViewController.h create mode 100644 MarsWater/MarsWater/TaskCreationTableViewController.m create mode 100644 MarsWater/MarsWater/TasksTableViewController.h create mode 100644 MarsWater/MarsWater/TasksTableViewController.m diff --git a/MarsWater/MarsWater.xcodeproj/project.pbxproj b/MarsWater/MarsWater.xcodeproj/project.pbxproj index a2f82e3..ea962d7 100644 --- a/MarsWater/MarsWater.xcodeproj/project.pbxproj +++ b/MarsWater/MarsWater.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 895332B61BC840F800FCAD52 /* TasksTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 895332B51BC840F800FCAD52 /* TasksTableViewController.m */; settings = {ASSET_TAGS = (); }; }; + 895332B91BC8428600FCAD52 /* TaskCreationTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 895332B81BC8428600FCAD52 /* TaskCreationTableViewController.m */; settings = {ASSET_TAGS = (); }; }; 8DA86CA91BC1AE57006C50BC /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DA86CA81BC1AE57006C50BC /* main.m */; }; 8DA86CAC1BC1AE57006C50BC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DA86CAB1BC1AE57006C50BC /* AppDelegate.m */; }; 8DA86CB21BC1AE57006C50BC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8DA86CB01BC1AE57006C50BC /* Main.storyboard */; }; @@ -22,6 +24,10 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 895332B41BC840F800FCAD52 /* TasksTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TasksTableViewController.h; sourceTree = ""; }; + 895332B51BC840F800FCAD52 /* TasksTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TasksTableViewController.m; sourceTree = ""; }; + 895332B71BC8428600FCAD52 /* TaskCreationTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TaskCreationTableViewController.h; sourceTree = ""; }; + 895332B81BC8428600FCAD52 /* TaskCreationTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TaskCreationTableViewController.m; sourceTree = ""; }; 8DA86CA41BC1AE57006C50BC /* MarsWater.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MarsWater.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8DA86CA81BC1AE57006C50BC /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 8DA86CAA1BC1AE57006C50BC /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -56,6 +62,13 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 89DE602A1BC85BD50029B2B5 /* LISTS VS TASKS */ = { + isa = PBXGroup; + children = ( + ); + name = "LISTS VS TASKS"; + sourceTree = ""; + }; 8DA86C9B1BC1AE57006C50BC = { isa = PBXGroup; children = ( @@ -78,6 +91,11 @@ 8DA86CD11BC1B329006C50BC /* Model */, 8DA86CAA1BC1AE57006C50BC /* AppDelegate.h */, 8DA86CAB1BC1AE57006C50BC /* AppDelegate.m */, + 895332B41BC840F800FCAD52 /* TasksTableViewController.h */, + 895332B51BC840F800FCAD52 /* TasksTableViewController.m */, + 895332B71BC8428600FCAD52 /* TaskCreationTableViewController.h */, + 895332B81BC8428600FCAD52 /* TaskCreationTableViewController.m */, + 89DE602A1BC85BD50029B2B5 /* LISTS VS TASKS */, 8DA86CD21BC1B8E4006C50BC /* ListsTableViewController.h */, 8DA86CD31BC1B8E4006C50BC /* ListsTableViewController.m */, 8DA86CD51BC1B904006C50BC /* ListCreationTableViewController.h */, @@ -187,10 +205,12 @@ files = ( 8DA86CB51BC1AE57006C50BC /* MarsWater.xcdatamodeld in Sources */, 8DA86CAC1BC1AE57006C50BC /* AppDelegate.m in Sources */, + 895332B91BC8428600FCAD52 /* TaskCreationTableViewController.m in Sources */, 8DB2F6EA1BC1E75500E58E65 /* Task+CoreDataProperties.m in Sources */, 8DA86CD41BC1B8E4006C50BC /* ListsTableViewController.m in Sources */, 8DB2F6E71BC1E75500E58E65 /* List.m in Sources */, 8DB2F6E91BC1E75500E58E65 /* Task.m in Sources */, + 895332B61BC840F800FCAD52 /* TasksTableViewController.m in Sources */, 8DA86CD71BC1B904006C50BC /* ListCreationTableViewController.m in Sources */, 8DA86CA91BC1AE57006C50BC /* main.m in Sources */, 8DB2F6E81BC1E75500E58E65 /* List+CoreDataProperties.m in Sources */, diff --git a/MarsWater/MarsWater/Base.lproj/Main.storyboard b/MarsWater/MarsWater/Base.lproj/Main.storyboard index 13ead89..51242fe 100644 --- a/MarsWater/MarsWater/Base.lproj/Main.storyboard +++ b/MarsWater/MarsWater/Base.lproj/Main.storyboard @@ -8,32 +8,32 @@ - + - - + + - + @@ -41,6 +41,9 @@ + + + @@ -58,7 +61,83 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -75,7 +154,7 @@ - + @@ -93,7 +172,7 @@ - + - + @@ -126,7 +205,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MarsWater/MarsWater/ListCreationTableViewController.m b/MarsWater/MarsWater/ListCreationTableViewController.m index 0ecf6e9..1b71bbb 100644 --- a/MarsWater/MarsWater/ListCreationTableViewController.m +++ b/MarsWater/MarsWater/ListCreationTableViewController.m @@ -57,7 +57,14 @@ - (void)save { } - (IBAction)colorButtonTapped:(UIButton *)sender { + self.list.color = sender.backgroundColor; } + + + + + + @end diff --git a/MarsWater/MarsWater/ListsTableViewController.m b/MarsWater/MarsWater/ListsTableViewController.m index 8a2659c..504d08d 100644 --- a/MarsWater/MarsWater/ListsTableViewController.m +++ b/MarsWater/MarsWater/ListsTableViewController.m @@ -65,12 +65,29 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.detailTextLabel.text = [list.createdAt description]; return cell; + } -- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { - - [self.tableView reloadData]; -} + + +//#pragma mark - delete row from table view +// +//- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { +// return YES; +//} +// +//// +////- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { +//// +//// if (editingStyle == UITableViewCellEditingStyleDelete) { +//// +//// //remove the deleted object from your data source. +//// //If your data source is an NSMutableArray, do this +//// [self.fetchedResultsController.fetchedObjects removeObjectAtIndex:indexPath.row]; +//// [tableView reloadData]; // tell table to refresh now +//// } +////} + @end diff --git a/MarsWater/MarsWater/MarsWater.xcdatamodeld/MarsWater.xcdatamodel/contents b/MarsWater/MarsWater/MarsWater.xcdatamodeld/MarsWater.xcdatamodel/contents index 116441d..9a24fb0 100644 --- a/MarsWater/MarsWater/MarsWater.xcdatamodeld/MarsWater.xcdatamodel/contents +++ b/MarsWater/MarsWater/MarsWater.xcdatamodeld/MarsWater.xcdatamodel/contents @@ -16,7 +16,7 @@ - + \ No newline at end of file diff --git a/MarsWater/MarsWater/Task+CoreDataProperties.h b/MarsWater/MarsWater/Task+CoreDataProperties.h index 2cc11d7..0f8ae2d 100644 --- a/MarsWater/MarsWater/Task+CoreDataProperties.h +++ b/MarsWater/MarsWater/Task+CoreDataProperties.h @@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nullable, nonatomic, retain) NSDate *updatedAt; @property (nullable, nonatomic, retain) NSNumber *priority; @property (nullable, nonatomic, retain) NSDate *completedAt; +//@property (nullable, nonatomic, retain) id color; @property (nullable, nonatomic, retain) List *list; @end diff --git a/MarsWater/MarsWater/Task+CoreDataProperties.m b/MarsWater/MarsWater/Task+CoreDataProperties.m index 1ea972c..a9c26e2 100644 --- a/MarsWater/MarsWater/Task+CoreDataProperties.m +++ b/MarsWater/MarsWater/Task+CoreDataProperties.m @@ -20,5 +20,6 @@ @implementation Task (CoreDataProperties) @dynamic priority; @dynamic completedAt; @dynamic list; +//@dynamic color; @end diff --git a/MarsWater/MarsWater/TaskCreationTableViewController.h b/MarsWater/MarsWater/TaskCreationTableViewController.h new file mode 100644 index 0000000..bd196e7 --- /dev/null +++ b/MarsWater/MarsWater/TaskCreationTableViewController.h @@ -0,0 +1,13 @@ +// +// TaskCreationTableViewController.h +// MarsWater +// +// Created by Lauren Caponong on 10/9/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import + +@interface TaskCreationTableViewController : UITableViewController + +@end diff --git a/MarsWater/MarsWater/TaskCreationTableViewController.m b/MarsWater/MarsWater/TaskCreationTableViewController.m new file mode 100644 index 0000000..6b7fe31 --- /dev/null +++ b/MarsWater/MarsWater/TaskCreationTableViewController.m @@ -0,0 +1,83 @@ +// +// TaskCreationTableViewController.m +// MarsWater +// +// Created by Lauren Caponong on 10/9/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import +#import "TaskCreationTableViewController.h" +#import "Task.h" +#import "AppDelegate.h" + + +// TASK PROPERTIES + + //@property (nullable, nonatomic, retain) NSString *taskDescription; + //@property (nullable, nonatomic, retain) NSDate *createdAt; + //@property (nullable, nonatomic, retain) NSDate *dueAt; + //@property (nullable, nonatomic, retain) NSDate *updatedAt; + //@property (nullable, nonatomic, retain) NSNumber *priority; + //@property (nullable, nonatomic, retain) NSDate *completedAt; + //@property (nullable, nonatomic, retain) id color; + //@property (nullable, nonatomic, retain) List *list; + + + + +@interface TaskCreationTableViewController () + +@property (weak, nonatomic) IBOutlet UITextField *titleTextField; +@property (nonatomic) Task *task; + +@end + + + +@implementation TaskCreationTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + [self setupNavigationBar]; + + AppDelegate *delegate = [UIApplication sharedApplication].delegate; + + self.task = [NSEntityDescription insertNewObjectForEntityForName:@"Task" inManagedObjectContext:delegate.managedObjectContext]; +} + +- (void)setupNavigationBar { + + self.navigationItem.title = @"Create New Task"; + + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)]; + + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save)]; + + // set the right button to save +} + +- (void)cancel { + [self dismissViewControllerAnimated:YES completion:nil]; +} + +- (void)save { + self.task.taskDescription = self.titleTextField.text; + self.task.createdAt = [NSDate date]; + + AppDelegate *delegate = [UIApplication sharedApplication].delegate; + [delegate.managedObjectContext save:nil]; + + [self dismissViewControllerAnimated:YES completion:nil]; +} + +//- (IBAction)colorButtonTapped:(UIButton *)sender { +// +// self.task.color = sender.backgroundColor; +// +//} + + +@end + diff --git a/MarsWater/MarsWater/TasksTableViewController.h b/MarsWater/MarsWater/TasksTableViewController.h new file mode 100644 index 0000000..bb2fa83 --- /dev/null +++ b/MarsWater/MarsWater/TasksTableViewController.h @@ -0,0 +1,13 @@ +// +// TasksTableViewController.h +// MarsWater +// +// Created by Lauren Caponong on 10/9/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import + +@interface TasksTableViewController : UITableViewController + +@end diff --git a/MarsWater/MarsWater/TasksTableViewController.m b/MarsWater/MarsWater/TasksTableViewController.m new file mode 100644 index 0000000..ae089f6 --- /dev/null +++ b/MarsWater/MarsWater/TasksTableViewController.m @@ -0,0 +1,82 @@ +// +// TasksTableViewController.m +// MarsWater +// +// Created by Lauren Caponong on 10/9/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import +#import "TasksTableViewController.h" +#import "AppDelegate.h" +#import "Task.h" + +@interface TasksTableViewController () + +@property (nonatomic) NSFetchedResultsController *fetchedResultsController; + +@end + +@implementation TasksTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + + AppDelegate *delegate = [UIApplication sharedApplication].delegate; + + // 1) create an instance of NSFetchRequest with an entity name + NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Task"]; + + + // 2) create a sort descriptor + NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"createdAt" ascending:NO]; + + // 3) set the sortDescriptors on the fetchRequest + fetchRequest.sortDescriptors = @[sort]; + + // 4) create a fetchedResultsController with a fetchRequest and a managedObjectContext, + self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:delegate.managedObjectContext sectionNameKeyPath:nil cacheName:nil]; + + self.fetchedResultsController.delegate = self; + + [self.fetchedResultsController performFetch:nil]; + + [self.tableView reloadData]; +} + + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.fetchedResultsController.fetchedObjects.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"TaskCellIdentifier" forIndexPath:indexPath]; + + Task *task = self.fetchedResultsController.fetchedObjects[indexPath.row]; + +// cell.backgroundColor = (UIColor *)task.color; + + cell.textLabel.text = task.taskDescription; + + NSString *taskCreatedAtTime = [task.createdAt description]; + cell.detailTextLabel.text = taskCreatedAtTime; + + return cell; +} + +- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { + + [self.tableView reloadData]; +} + + + + +@end \ No newline at end of file From 8546d50be68bbb47add5164643529d037c11214c Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 9 Oct 2015 22:06:38 -0400 Subject: [PATCH 2/3] Fixed a few bugs --- .../MarsWater/Base.lproj/Main.storyboard | 80 +------------------ .../MarsWater/ListsTableViewController.m | 35 ++++---- .../MarsWater/TasksTableViewController.m | 2 + 3 files changed, 21 insertions(+), 96 deletions(-) diff --git a/MarsWater/MarsWater/Base.lproj/Main.storyboard b/MarsWater/MarsWater/Base.lproj/Main.storyboard index 51242fe..d48dd65 100644 --- a/MarsWater/MarsWater/Base.lproj/Main.storyboard +++ b/MarsWater/MarsWater/Base.lproj/Main.storyboard @@ -42,7 +42,7 @@ - + @@ -120,7 +120,7 @@ - + @@ -356,82 +356,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/MarsWater/MarsWater/ListsTableViewController.m b/MarsWater/MarsWater/ListsTableViewController.m index 504d08d..6fae75a 100644 --- a/MarsWater/MarsWater/ListsTableViewController.m +++ b/MarsWater/MarsWater/ListsTableViewController.m @@ -11,7 +11,7 @@ #import "AppDelegate.h" #import "List.h" -@interface ListsTableViewController () +@interface ListsTableViewController () @property (nonatomic) NSFetchedResultsController *fetchedResultsController; @@ -20,6 +20,7 @@ @interface ListsTableViewController () @implementation ListsTableViewController - (void)viewDidLoad { + [super viewDidLoad]; @@ -53,6 +54,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.fetchedResultsController.fetchedObjects.count; } @@ -70,23 +72,20 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N -//#pragma mark - delete row from table view -// -//- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { -// return YES; -//} -// -//// -////- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { -//// -//// if (editingStyle == UITableViewCellEditingStyleDelete) { -//// -//// //remove the deleted object from your data source. -//// //If your data source is an NSMutableArray, do this -//// [self.fetchedResultsController.fetchedObjects removeObjectAtIndex:indexPath.row]; -//// [tableView reloadData]; // tell table to refresh now -//// } -////} +- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { + + [self.tableView reloadData]; +} + + + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + NSLog(@"%ld", (long)indexPath.row); // you can see selected row number in your console; + + + +} @end diff --git a/MarsWater/MarsWater/TasksTableViewController.m b/MarsWater/MarsWater/TasksTableViewController.m index ae089f6..b07ab7f 100644 --- a/MarsWater/MarsWater/TasksTableViewController.m +++ b/MarsWater/MarsWater/TasksTableViewController.m @@ -71,6 +71,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N return cell; } + + - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { [self.tableView reloadData]; From bbb792273f3927ae6404677f0bcc005281d510a8 Mon Sep 17 00:00:00 2001 From: Lauren Date: Fri, 9 Oct 2015 22:17:00 -0400 Subject: [PATCH 3/3] Added tableView reloadData --- MarsWater/MarsWater/ListsTableViewController.m | 13 ++++++++----- MarsWater/MarsWater/TasksTableViewController.h | 3 +++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/MarsWater/MarsWater/ListsTableViewController.m b/MarsWater/MarsWater/ListsTableViewController.m index 6fae75a..83dd4d9 100644 --- a/MarsWater/MarsWater/ListsTableViewController.m +++ b/MarsWater/MarsWater/ListsTableViewController.m @@ -8,6 +8,7 @@ #import #import "ListsTableViewController.h" +#import "TasksTableViewController.h" #import "AppDelegate.h" #import "List.h" @@ -79,12 +80,14 @@ - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id) -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath -{ - NSLog(@"%ld", (long)indexPath.row); // you can see selected row number in your console; - - +-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ + if ([segue.identifier isEqualToString:@"taskSegue"]) { + NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; + + TasksTableViewController *tvcForTasks = segue.destinationViewController; + tvcForTasks.list = self.fetchedResultsController.fetchedObjects[indexPath.row]; + } } diff --git a/MarsWater/MarsWater/TasksTableViewController.h b/MarsWater/MarsWater/TasksTableViewController.h index bb2fa83..f74b6e0 100644 --- a/MarsWater/MarsWater/TasksTableViewController.h +++ b/MarsWater/MarsWater/TasksTableViewController.h @@ -7,7 +7,10 @@ // #import +#import "List.h" @interface TasksTableViewController : UITableViewController +@property (nonatomic) List *list; + @end