Commit 8e9c360b authored by tybrandt's avatar tybrandt
Browse files

Implemented deletion of individual transactions and redesigned the Deletion View

parent f693c40d
......@@ -18,11 +18,12 @@ class AddTransactionViewController: UIViewController, UITextFieldDelegate, UINav
override func viewDidLoad() {
super.viewDidLoad()
isModalInPresentation = true
addButton.isEnabled = false
categoryTextField.delegate = self
nameTextField.delegate = self
costTextField.delegate = self
addDoneButtonToKeyboard(myAction: #selector(costTextField.resignFirstResponder))
addDoneButtonToKeyboard(myAction: #selector(costTextField.resignFirstResponder))
NotificationCenter.default.addObserver(self,
selector: #selector(AddTransactionViewController.keyboardWillShow),
name: UIResponder.keyboardWillShowNotification, object: nil)
......
......@@ -129,8 +129,8 @@
<outlet property="categoryTable" destination="2vd-QX-gXm" id="RVa-T8-OWz"/>
<outlet property="totalLabel" destination="bay-ph-RNu" id="2af-D9-cpa"/>
<segue destination="JIR-F4-P6s" kind="presentation" identifier="addTransaction" id="4xG-2T-kn9"/>
<segue destination="fMk-k4-n9V" kind="show" identifier="showTransactions" id="fjM-Ke-YRf"/>
<segue destination="S1V-KR-a3v" kind="presentation" identifier="showDelete" id="Pg9-7d-59Z"/>
<segue destination="2i0-KG-j1T" kind="presentation" identifier="confirmDelete" id="OPk-vX-Zez"/>
<segue destination="G1A-Zz-7cZ" kind="show" identifier="showTransactions" id="ssQ-4I-uh1"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
......@@ -218,17 +218,11 @@
<outlet property="delegate" destination="G1A-Zz-7cZ" id="v5d-PW-7nE"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="All Transactions" id="xym-6q-kXb">
<barButtonItem key="leftBarButtonItem" systemItem="done" id="8Tp-4a-EE7">
<connections>
<action selector="goBack:" destination="G1A-Zz-7cZ" id="sRB-vx-BSN"/>
</connections>
</barButtonItem>
</navigationItem>
<navigationItem key="navigationItem" title="All Transactions" id="xym-6q-kXb"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Vnp-er-RtW" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2811.594202898551" y="164.73214285714286"/>
<point key="canvasLocation" x="1848" y="165"/>
</scene>
<!--Delete All Confirmation-->
<scene sceneID="a5z-6h-cFL">
......@@ -238,42 +232,67 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="842"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="WARNING: This will delete all transactions. Proceed?" lineBreakMode="tailTruncation" numberOfLines="10" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="H6G-mT-H8f">
<rect key="frame" x="20" y="76" width="374" height="57.5"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="5ck-f4-XMy">
<rect key="frame" x="35.5" y="357" width="343" height="128"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="WARNING: This will delete all transactions. Proceed?" lineBreakMode="tailTruncation" numberOfLines="10" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="H6G-mT-H8f">
<rect key="frame" x="8" y="8" width="315" height="57.5"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iqe-4U-xvd">
<rect key="frame" x="252" y="74" width="71" height="36"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<state key="normal" title="Confirm"/>
<connections>
<segue destination="b7c-FZ-HVQ" kind="unwind" unwindAction="deleteDataWithSender:" id="xXf-uG-j6P"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="T85-yI-fGz">
<rect key="frame" x="8" y="74" width="61" height="36"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<state key="normal" title="Cancel"/>
<connections>
<action selector="cancel:" destination="2i0-KG-j1T" eventType="touchUpInside" id="dEs-aq-g9D"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="T85-yI-fGz" secondAttribute="bottom" constant="8" id="0Nc-PY-E4U"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="H6G-mT-H8f" secondAttribute="bottom" constant="1" id="798-Fn-nhp"/>
<constraint firstItem="iqe-4U-xvd" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="5ck-f4-XMy" secondAttribute="leading" constant="1" id="A2G-2w-tYB"/>
<constraint firstAttribute="trailing" secondItem="iqe-4U-xvd" secondAttribute="trailing" constant="20" symbolic="YES" id="B8O-Rk-rBc"/>
<constraint firstItem="H6G-mT-H8f" firstAttribute="top" secondItem="5ck-f4-XMy" secondAttribute="top" constant="8" id="DyP-As-s0S"/>
<constraint firstItem="H6G-mT-H8f" firstAttribute="leading" secondItem="5ck-f4-XMy" secondAttribute="leading" constant="8" id="HRg-vt-0RF"/>
<constraint firstItem="iqe-4U-xvd" firstAttribute="top" secondItem="5ck-f4-XMy" secondAttribute="top" constant="74" id="PqW-t7-mhw"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="iqe-4U-xvd" secondAttribute="bottom" constant="8" id="TdD-rA-aNv"/>
<constraint firstItem="T85-yI-fGz" firstAttribute="leading" secondItem="5ck-f4-XMy" secondAttribute="leading" constant="8" id="bhW-V3-XyB"/>
<constraint firstAttribute="width" constant="343" id="emt-Yb-YpT"/>
<constraint firstItem="iqe-4U-xvd" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="T85-yI-fGz" secondAttribute="trailing" constant="8" id="iKj-sd-mRg"/>
<constraint firstAttribute="height" constant="128" id="n39-Su-ZLl"/>
<constraint firstAttribute="trailing" secondItem="H6G-mT-H8f" secondAttribute="trailing" constant="20" symbolic="YES" id="qWI-zx-6kL"/>
<constraint firstItem="T85-yI-fGz" firstAttribute="top" secondItem="5ck-f4-XMy" secondAttribute="top" constant="74" id="tTW-Ie-cAk"/>
</constraints>
</view>
</subviews>
<viewLayoutGuide key="safeArea" id="wj6-tN-4pg"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="H6G-mT-H8f" firstAttribute="top" secondItem="wj6-tN-4pg" secondAttribute="top" constant="20" id="39c-Ar-HQM"/>
<constraint firstItem="H6G-mT-H8f" firstAttribute="leading" secondItem="wj6-tN-4pg" secondAttribute="leading" constant="20" id="3mB-Y0-gJH"/>
<constraint firstItem="wj6-tN-4pg" firstAttribute="trailing" secondItem="H6G-mT-H8f" secondAttribute="trailing" constant="20" id="Mao-Cr-6Bw"/>
<constraint firstItem="5ck-f4-XMy" firstAttribute="centerY" secondItem="SBD-pd-l3O" secondAttribute="centerY" id="J24-Lb-neC"/>
<constraint firstItem="5ck-f4-XMy" firstAttribute="centerX" secondItem="SBD-pd-l3O" secondAttribute="centerX" id="PJ2-nr-1a7"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Delete All Confirmation" id="sva-iT-2r1">
<barButtonItem key="leftBarButtonItem" systemItem="cancel" id="68X-b9-1aw">
<connections>
<action selector="cancel:" destination="2i0-KG-j1T" id="d1V-u5-tXa"/>
</connections>
</barButtonItem>
<barButtonItem key="rightBarButtonItem" title="Confirm" id="foO-CN-S4s">
<connections>
<action selector="confirm:" destination="2i0-KG-j1T" id="Ubw-cj-tI6"/>
<segue destination="b7c-FZ-HVQ" kind="unwind" unwindAction="deleteDataWithSender:" id="FNS-Z8-p7X"/>
</connections>
</barButtonItem>
</navigationItem>
<navigationItem key="navigationItem" title="Delete All Confirmation" id="sva-iT-2r1"/>
<connections>
<outlet property="confirmButton" destination="foO-CN-S4s" id="7pi-si-SMG"/>
<outlet property="confirmButton" destination="iqe-4U-xvd" id="pKa-F6-cLv"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="qmn-NT-Tu8" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
<exit id="b7c-FZ-HVQ" userLabel="Exit" sceneMemberID="exit"/>
</objects>
<point key="canvasLocation" x="2811.594202898551" y="906.69642857142856"/>
<point key="canvasLocation" x="1847.826086956522" y="894.64285714285711"/>
</scene>
<!--Add Transaction-->
<scene sceneID="jMr-WU-dY7">
......@@ -375,43 +394,6 @@
</objects>
<point key="canvasLocation" x="1848" y="-575"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="FS8-hY-hF7">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="fMk-k4-n9V" sceneMemberID="viewController">
<toolbarItems/>
<navigationItem key="navigationItem" id="JYS-JJ-2My"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="VIw-U5-2AY">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="G1A-Zz-7cZ" kind="relationship" relationship="rootViewController" id="SIE-hr-SbD"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="pSl-yP-Ti1" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1848" y="165"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="sGw-qv-EVz">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="S1V-KR-a3v" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="ECZ-bt-BA7">
<rect key="frame" x="0.0" y="0.0" width="414" height="56"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="2i0-KG-j1T" kind="relationship" relationship="rootViewController" id="M5A-jm-7U6"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="g2y-ep-vTd" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1848" y="907"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
......
......@@ -39,7 +39,7 @@ class CategoryViewController: UIViewController, UITableViewDelegate, UITableView
}
@IBAction func confirmDelete(_ sender: UIButton) {
performSegue(withIdentifier: "showDelete", sender: self)
performSegue(withIdentifier: "confirmDelete", sender: self)
}
@IBAction func displayData(sender: UIStoryboardSegue) {
......@@ -77,8 +77,7 @@ class CategoryViewController: UIViewController, UITableViewDelegate, UITableView
addView.categories = categories
addView.transactions = transactions
case "showTransactions":
guard let showViewNav = segue.destination as? UINavigationController else {return}
guard let showView = showViewNav.viewControllers.first as? TransactionTableViewController else {return}
guard let showView = segue.destination as? TransactionTableViewController else {return}
showView.transactions = transactions
default:
return
......@@ -104,6 +103,33 @@ class CategoryViewController: UIViewController, UITableViewDelegate, UITableView
cell.price.text = String(format: "$%.2f", category.price)
return cell
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle,
forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let category = categories[indexPath.row]
var i = 0
for transaction in transactions {
if transaction.category == category.name {
transactions.remove(at: i)
i -= 1
}
i += 1
}
categories.remove(at: indexPath.row)
saveData();
categoryTable.reloadData()
var total = 0.0
for cat in categories {
total += cat.price
}
totalLabel.text = String(format: "Total: $%.2f", total)
}
}
private func saveData() {
do {
......
......@@ -9,19 +9,20 @@ import UIKit
class DeletionViewController: UIViewController {
var confirmed = false
@IBOutlet weak var confirmButton: UIBarButtonItem!
@IBOutlet weak var confirmButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
isModalInPresentation = true
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
guard let button = sender as? UIBarButtonItem, button === confirmButton else {return}
guard let button = sender as? UIButton, button === confirmButton else {return}
confirmed = true
}
@IBAction func cancel(_ sender: UIBarButtonItem) {
@IBAction func cancel(_ sender: UIButton) {
dismiss(animated: true, completion: nil)
}
......
......@@ -43,9 +43,5 @@ class TransactionTableViewController: UITableViewController {
cell.date.text = transaction.date
return cell
}
@IBAction func goBack(_ sender: UIBarButtonItem) {
dismiss(animated: true, completion: nil)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment