diff --git a/MarsWater/MarsWater.xcodeproj/project.pbxproj b/MarsWater/MarsWater.xcodeproj/project.pbxproj index a2f82e3..3e365b8 100644 --- a/MarsWater/MarsWater.xcodeproj/project.pbxproj +++ b/MarsWater/MarsWater.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 0B64CA0D1BC61067005928CE /* TaskViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0B64CA0C1BC61067005928CE /* TaskViewController.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 +23,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 0B64CA0B1BC61067005928CE /* TaskViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TaskViewController.h; sourceTree = ""; }; + 0B64CA0C1BC61067005928CE /* TaskViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TaskViewController.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 = ""; }; @@ -82,6 +85,8 @@ 8DA86CD31BC1B8E4006C50BC /* ListsTableViewController.m */, 8DA86CD51BC1B904006C50BC /* ListCreationTableViewController.h */, 8DA86CD61BC1B904006C50BC /* ListCreationTableViewController.m */, + 0B64CA0B1BC61067005928CE /* TaskViewController.h */, + 0B64CA0C1BC61067005928CE /* TaskViewController.m */, 8DA86CB01BC1AE57006C50BC /* Main.storyboard */, 8DA86CB61BC1AE57006C50BC /* Assets.xcassets */, 8DA86CB81BC1AE57006C50BC /* LaunchScreen.storyboard */, @@ -192,6 +197,7 @@ 8DB2F6E71BC1E75500E58E65 /* List.m in Sources */, 8DB2F6E91BC1E75500E58E65 /* Task.m in Sources */, 8DA86CD71BC1B904006C50BC /* ListCreationTableViewController.m in Sources */, + 0B64CA0D1BC61067005928CE /* TaskViewController.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..3de1f95 100644 --- a/MarsWater/MarsWater/Base.lproj/Main.storyboard +++ b/MarsWater/MarsWater/Base.lproj/Main.storyboard @@ -26,7 +26,7 @@ - + @@ -85,7 +85,7 @@ - + @@ -100,7 +100,7 @@ - + @@ -215,6 +215,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MarsWater/MarsWater/List+CoreDataProperties.h b/MarsWater/MarsWater/List+CoreDataProperties.h index 9ce8d06..7063456 100644 --- a/MarsWater/MarsWater/List+CoreDataProperties.h +++ b/MarsWater/MarsWater/List+CoreDataProperties.h @@ -10,6 +10,7 @@ // #import "List.h" +#import "Task.h" NS_ASSUME_NONNULL_BEGIN @@ -18,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nullable, nonatomic, retain) NSString *title; @property (nullable, nonatomic, retain) NSDate *createdAt; @property (nullable, nonatomic, retain) id color; -@property (nullable, nonatomic, retain) NSArray *task; +@property (nullable, nonatomic, retain) NSMutableOrderedSet *task; @end diff --git a/MarsWater/MarsWater/ListsTableViewController.m b/MarsWater/MarsWater/ListsTableViewController.m index 8a2659c..7adc200 100644 --- a/MarsWater/MarsWater/ListsTableViewController.m +++ b/MarsWater/MarsWater/ListsTableViewController.m @@ -10,6 +10,7 @@ #import "ListsTableViewController.h" #import "AppDelegate.h" #import "List.h" +#import "TaskViewController.h" @interface ListsTableViewController () @@ -67,6 +68,28 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N return cell; } +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + + List *list = self.fetchedResultsController.fetchedObjects[indexPath.row]; + + TaskViewController *taskvc = [self.storyboard instantiateViewControllerWithIdentifier:@"TaskViewController"]; + taskvc.list = list; + + [self.navigationController pushViewController:taskvc animated:YES]; + +} + + + +- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { + if (editingStyle == UITableViewCellEditingStyleDelete) { + NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath]; +// [self.managedObjectContext deleteObject:]; +// [self.managedObjectContext save:nil]; + + } +} + - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { [self.tableView reloadData]; diff --git a/MarsWater/MarsWater/TaskViewController.h b/MarsWater/MarsWater/TaskViewController.h new file mode 100644 index 0000000..e43dd90 --- /dev/null +++ b/MarsWater/MarsWater/TaskViewController.h @@ -0,0 +1,15 @@ +// +// TaskViewController.h +// MarsWater +// +// Created by Artur Lan on 10/7/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import +#import "List.h" + +@interface TaskViewController : UIViewController +@property (nonatomic) List *list; + +@end diff --git a/MarsWater/MarsWater/TaskViewController.m b/MarsWater/MarsWater/TaskViewController.m new file mode 100644 index 0000000..77dfc1b --- /dev/null +++ b/MarsWater/MarsWater/TaskViewController.m @@ -0,0 +1,65 @@ +// +// TaskViewController.m +// MarsWater +// +// Created by Artur Lan on 10/7/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "TaskViewController.h" +#import "AppDelegate.h" + +@interface TaskViewController () + +@property (weak, nonatomic) IBOutlet UITextField *textField; +@property (weak, nonatomic) IBOutlet UITableView *tableView; +@end + +@implementation TaskViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + self.navigationItem.title = @"Task"; + + self.tableView.dataSource = self; + self.textField.delegate = self; + + +} + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.list.task.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier" forIndexPath:indexPath]; + + Task *task = self.list.task[indexPath.row]; + cell.textLabel.text = task.taskDescription; + + return cell; +} + +- (BOOL)textFieldShouldReturn:(UITextField *)textField { + + [textField endEditing:YES]; + + AppDelegate *delegate = [UIApplication sharedApplication].delegate; + Task *task = [NSEntityDescription insertNewObjectForEntityForName:@"Task" inManagedObjectContext:self.list.managedObjectContext]; + + task.taskDescription = textField.text; + [self.list.task addObject:task]; + [delegate.managedObjectContext save:nil]; + + textField.text = @""; + [self.tableView reloadData]; + + return YES; +} + +@end