Skip to content

Commit ed5a7c1

Browse files
author
Bart Jacobs
committed
Create and implement NoteViewController
1 parent 52d3e30 commit ed5a7c1

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

Notes.xcodeproj/project.pbxproj

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
CC1047021E6FD9120062BF32 /* Notes.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = CC1047001E6FD9120062BF32 /* Notes.xcdatamodeld */; };
1616
CC1047041E6FDA670062BF32 /* CoreDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC1047031E6FDA670062BF32 /* CoreDataManager.swift */; };
1717
CC1047061E6FDAFD0062BF32 /* AddNoteViewContorller.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC1047051E6FDAFD0062BF32 /* AddNoteViewContorller.swift */; };
18+
CCE3AB3A1E6FF7FD003CC1B8 /* NoteViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCE3AB391E6FF7FD003CC1B8 /* NoteViewController.swift */; };
1819
/* End PBXBuildFile section */
1920

2021
/* Begin PBXFileReference section */
@@ -28,6 +29,7 @@
2829
CC1047011E6FD9120062BF32 /* Notes.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Notes.xcdatamodel; sourceTree = "<group>"; };
2930
CC1047031E6FDA670062BF32 /* CoreDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataManager.swift; sourceTree = "<group>"; };
3031
CC1047051E6FDAFD0062BF32 /* AddNoteViewContorller.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddNoteViewContorller.swift; sourceTree = "<group>"; };
32+
CCE3AB391E6FF7FD003CC1B8 /* NoteViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoteViewController.swift; sourceTree = "<group>"; };
3133
/* End PBXFileReference section */
3234

3335
/* Begin PBXFrameworksBuildPhase section */
@@ -62,6 +64,7 @@
6264
children = (
6365
CC1046EE1E6FD8780062BF32 /* AppDelegate.swift */,
6466
CC1046F01E6FD8780062BF32 /* ViewController.swift */,
67+
CCE3AB391E6FF7FD003CC1B8 /* NoteViewController.swift */,
6568
CC1047051E6FDAFD0062BF32 /* AddNoteViewContorller.swift */,
6669
CC1047031E6FDA670062BF32 /* CoreDataManager.swift */,
6770
CC1046F21E6FD8790062BF32 /* Main.storyboard */,
@@ -150,6 +153,7 @@
150153
CC1046F11E6FD8780062BF32 /* ViewController.swift in Sources */,
151154
CC1047021E6FD9120062BF32 /* Notes.xcdatamodeld in Sources */,
152155
CC1047041E6FDA670062BF32 /* CoreDataManager.swift in Sources */,
156+
CCE3AB3A1E6FF7FD003CC1B8 /* NoteViewController.swift in Sources */,
153157
CC1046EF1E6FD8780062BF32 /* AppDelegate.swift in Sources */,
154158
);
155159
runOnlyForDeploymentPostprocessing = 0;
@@ -312,6 +316,7 @@
312316
CC1046FF1E6FD8790062BF32 /* Release */,
313317
);
314318
defaultConfigurationIsVisible = 0;
319+
defaultConfigurationName = Release;
315320
};
316321
/* End XCConfigurationList section */
317322

Notes/Base.lproj/Main.storyboard

+60-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
2626
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
2727
<prototypes>
28-
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="NoteCell" textLabel="5zj-eO-Ahy" detailTextLabel="DtP-3h-hJA" style="IBUITableViewCellStyleSubtitle" id="z2O-Us-fQh">
28+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="NoteCell" textLabel="5zj-eO-Ahy" detailTextLabel="DtP-3h-hJA" style="IBUITableViewCellStyleSubtitle" id="z2O-Us-fQh">
2929
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
3030
<autoresizingMask key="autoresizingMask"/>
3131
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="z2O-Us-fQh" id="SyL-J3-i5m">
32-
<rect key="frame" x="0.0" y="0.0" width="375" height="43"/>
32+
<rect key="frame" x="0.0" y="0.0" width="342" height="43"/>
3333
<autoresizingMask key="autoresizingMask"/>
3434
<subviews>
3535
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="5zj-eO-Ahy">
@@ -48,6 +48,9 @@
4848
</label>
4949
</subviews>
5050
</tableViewCellContentView>
51+
<connections>
52+
<segue destination="bI8-wK-hAY" kind="show" identifier="SegueNoteViewController" id="zme-EL-60i"/>
53+
</connections>
5154
</tableViewCell>
5255
</prototypes>
5356
<connections>
@@ -79,6 +82,61 @@
7982
</objects>
8083
<point key="canvasLocation" x="908" y="70.614692653673174"/>
8184
</scene>
85+
<!--Note View Controller-->
86+
<scene sceneID="DS2-gj-2Yl">
87+
<objects>
88+
<viewController id="bI8-wK-hAY" customClass="NoteViewController" customModule="Notes" customModuleProvider="target" sceneMemberID="viewController">
89+
<layoutGuides>
90+
<viewControllerLayoutGuide type="top" id="okt-WC-RwW"/>
91+
<viewControllerLayoutGuide type="bottom" id="yjO-e4-hO7"/>
92+
</layoutGuides>
93+
<view key="view" contentMode="scaleToFill" id="prT-F8-Gn0">
94+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
95+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
96+
<subviews>
97+
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Uh4-ds-zQE">
98+
<rect key="frame" x="47.5" y="72" width="280" height="30"/>
99+
<constraints>
100+
<constraint firstAttribute="width" constant="280" id="nWv-8r-gZ4"/>
101+
</constraints>
102+
<nil key="textColor"/>
103+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
104+
<textInputTraits key="textInputTraits"/>
105+
</textField>
106+
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="PSU-Oo-Ikg">
107+
<rect key="frame" x="16" y="110" width="343" height="505"/>
108+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
109+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
110+
<string key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
111+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
112+
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
113+
</textView>
114+
</subviews>
115+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
116+
<constraints>
117+
<constraint firstItem="Uh4-ds-zQE" firstAttribute="top" secondItem="okt-WC-RwW" secondAttribute="bottom" constant="8" id="L6F-of-d1P"/>
118+
<constraint firstItem="Uh4-ds-zQE" firstAttribute="centerX" secondItem="prT-F8-Gn0" secondAttribute="centerX" id="cdi-Ch-eNQ"/>
119+
</constraints>
120+
</view>
121+
<toolbarItems>
122+
<barButtonItem title="Item" id="S7f-CO-VVb"/>
123+
</toolbarItems>
124+
<navigationItem key="navigationItem" id="gyc-IQ-fVL">
125+
<barButtonItem key="rightBarButtonItem" systemItem="save" id="8Ri-lH-cYq">
126+
<connections>
127+
<action selector="save:" destination="bI8-wK-hAY" id="giS-uY-D0K"/>
128+
</connections>
129+
</barButtonItem>
130+
</navigationItem>
131+
<connections>
132+
<outlet property="contentTextView" destination="PSU-Oo-Ikg" id="rT4-bf-oiS"/>
133+
<outlet property="titleTextField" destination="Uh4-ds-zQE" id="bge-RG-TUw"/>
134+
</connections>
135+
</viewController>
136+
<placeholder placeholderIdentifier="IBFirstResponder" id="dQh-Yk-wmk" userLabel="First Responder" sceneMemberID="firstResponder"/>
137+
</objects>
138+
<point key="canvasLocation" x="1677.5999999999999" y="70.614692653673174"/>
139+
</scene>
82140
<!--Navigation Controller-->
83141
<scene sceneID="9zq-hk-0Zy">
84142
<objects>

Notes/NoteViewController.swift

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// NoteViewController.swift
3+
// Notes
4+
//
5+
// Created by Bart Jacobs on 08/03/2017.
6+
// Copyright © 2017 Cocoacasts. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class NoteViewController: UIViewController {
12+
13+
// MARK: - Properties
14+
15+
@IBOutlet var titleTextField: UITextField!
16+
@IBOutlet var contentTextView: UITextView!
17+
18+
// MARK: -
19+
20+
var note: Note?
21+
22+
// MARK: - View Life Cycle
23+
24+
override func viewWillAppear(_ animated: Bool) {
25+
super.viewWillAppear(animated)
26+
27+
// Update User Interface
28+
titleTextField.text = note?.title
29+
contentTextView.text = note?.content
30+
}
31+
32+
// MARK: - Actions
33+
34+
@IBAction func save(_ sender: Any) {
35+
guard let title = titleTextField.text else { return }
36+
guard let content = contentTextView.text else { return }
37+
38+
// Update Note
39+
note?.title = title
40+
note?.content = content
41+
note?.updatedAt = NSDate()
42+
43+
// Pop View Controller From Navigation Stack
44+
_ = navigationController?.popViewController(animated: true)
45+
}
46+
47+
}

0 commit comments

Comments
 (0)