Skip to content

homework #27

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

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
6 changes: 6 additions & 0 deletions MarsWater/MarsWater.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 = "<group>"; };
0B64CA0C1BC61067005928CE /* TaskViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TaskViewController.m; sourceTree = "<group>"; };
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 = "<group>"; };
8DA86CAA1BC1AE57006C50BC /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
);
Expand Down
87 changes: 83 additions & 4 deletions MarsWater/MarsWater/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Subtitle" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="v9C-RD-f0m">
<rect key="frame" x="15" y="25" width="41" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand Down Expand Up @@ -85,7 +85,7 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
<sections>
<tableViewSection id="fjY-Uh-Pld">
<cells>
Expand All @@ -100,7 +100,7 @@
<rect key="frame" x="15" y="11" width="38" height="21"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="pGs-E0-Itl">
Expand Down Expand Up @@ -215,6 +215,85 @@
</objects>
<point key="canvasLocation" x="2405" y="205"/>
</scene>
<!--Task View Controller-->
<scene sceneID="Hdy-BL-CBn">
<objects>
<viewController storyboardIdentifier="TaskViewController" id="Wpw-1y-6f4" customClass="TaskViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="1HR-zP-EKu"/>
<viewControllerLayoutGuide type="bottom" id="PKl-Mh-Hva"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="bdZ-bd-xLh">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="3P1-cM-5hV">
<rect key="frame" x="0.0" y="102" width="600" height="498"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="CellIdentifier" id="9jV-Ok-xgN">
<rect key="frame" x="0.0" y="92" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="9jV-Ok-xgN" id="hNL-2M-kNV">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</tableViewCellContentView>
<animations/>
</tableViewCell>
</prototypes>
</tableView>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="tasks, items, etc....." textAlignment="natural" clearsOnBeginEditing="YES" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="2Kc-ni-4Oe">
<rect key="frame" x="5" y="72" width="590" height="30"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="30" id="ymb-Xg-DYm"/>
</constraints>
<color key="textColor" red="0.43529411759999997" green="0.4431372549" blue="0.47450980390000003" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="2Kc-ni-4Oe" secondAttribute="trailing" constant="5" id="5Aj-S1-rec"/>
<constraint firstItem="2Kc-ni-4Oe" firstAttribute="leading" secondItem="bdZ-bd-xLh" secondAttribute="leading" constant="5" id="8K2-Dv-VSw"/>
<constraint firstItem="2Kc-ni-4Oe" firstAttribute="top" secondItem="1HR-zP-EKu" secondAttribute="bottom" constant="8" id="IeP-50-OLB"/>
<constraint firstItem="3P1-cM-5hV" firstAttribute="top" secondItem="2Kc-ni-4Oe" secondAttribute="bottom" id="cSc-aQ-aRS"/>
<constraint firstItem="3P1-cM-5hV" firstAttribute="leading" secondItem="bdZ-bd-xLh" secondAttribute="leading" id="ewH-Aq-ycI"/>
<constraint firstItem="PKl-Mh-Hva" firstAttribute="top" secondItem="3P1-cM-5hV" secondAttribute="bottom" id="fQi-6q-gDV"/>
<constraint firstAttribute="trailing" secondItem="3P1-cM-5hV" secondAttribute="trailing" id="h7N-k8-muO"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="2JD-Ia-SgB"/>
<connections>
<outlet property="tableView" destination="3P1-cM-5hV" id="2E1-Ki-pcV"/>
<outlet property="textField" destination="2Kc-ni-4Oe" id="pLt-R7-Zvr"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="CTb-F5-Z3P" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2405" y="939"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="n9b-rK-A4N">
<objects>
<navigationController id="Kcd-Ce-8hk" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="g58-8i-Udv">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</navigationBar>
<connections>
<segue destination="Wpw-1y-6f4" kind="relationship" relationship="rootViewController" id="2T4-LF-ZhO"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="qlY-Mk-440" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1760" y="939"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="5nr-jx-cZX">
<objects>
Expand Down
3 changes: 2 additions & 1 deletion MarsWater/MarsWater/List+CoreDataProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//

#import "List.h"
#import "Task.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -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*> *task;

@end

Expand Down
23 changes: 23 additions & 0 deletions MarsWater/MarsWater/ListsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "ListsTableViewController.h"
#import "AppDelegate.h"
#import "List.h"
#import "TaskViewController.h"

@interface ListsTableViewController () <NSFetchedResultsControllerDelegate>

Expand Down Expand Up @@ -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];
Expand Down
15 changes: 15 additions & 0 deletions MarsWater/MarsWater/TaskViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// TaskViewController.h
// MarsWater
//
// Created by Artur Lan on 10/7/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
//

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

@interface TaskViewController : UIViewController
@property (nonatomic) List *list;

@end
65 changes: 65 additions & 0 deletions MarsWater/MarsWater/TaskViewController.m
Original file line number Diff line number Diff line change
@@ -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 () <UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate>

@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