Commit 35aaf8a1 authored by Zach Knox's avatar Zach Knox
Browse files

filter view sort selection checking works

that was a lot more work than I anticipated for doing that, but it works now!
parent daa5c707
......@@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
62C83AD91AF879227B0E6F76 /* Pods_WhatsOpen.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6465D077C7E63538B5736D27 /* Pods_WhatsOpen.framework */; };
7F4743271E11D1BC00E6E3D1 /* MainTableViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F4743261E11D1BC00E6E3D1 /* MainTableViewControllerTests.swift */; };
92108A331ED755F100675E16 /* CheckingTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92108A321ED755F100675E16 /* CheckingTableViewCell.swift */; };
92182EC01E95BD2C00192ABA /* LocationsListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92182EBF1E95BD2C00192ABA /* LocationsListViewController.swift */; };
92182EC41E95C38400192ABA /* LocationDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92182EC31E95C38400192ABA /* LocationDetailViewController.swift */; };
924840F81EA915F200DBFF4E /* SRCTSimpleCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924840F71EA915F200DBFF4E /* SRCTSimpleCollectionViewCell.swift */; };
......@@ -57,6 +58,7 @@
7F4743181E11C7D100E6E3D1 /* WhatsOpenTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WhatsOpenTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7F47431C1E11C7D100E6E3D1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7F4743261E11D1BC00E6E3D1 /* MainTableViewControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainTableViewControllerTests.swift; sourceTree = "<group>"; };
92108A321ED755F100675E16 /* CheckingTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckingTableViewCell.swift; sourceTree = "<group>"; };
92182EBF1E95BD2C00192ABA /* LocationsListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationsListViewController.swift; sourceTree = "<group>"; };
92182EC31E95C38400192ABA /* LocationDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationDetailViewController.swift; sourceTree = "<group>"; };
924840F71EA915F200DBFF4E /* SRCTSimpleCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SRCTSimpleCollectionViewCell.swift; sourceTree = "<group>"; };
......@@ -142,6 +144,7 @@
927C80DB1EB18B89009079AD /* FiltersTableViewController.swift */,
9270A4DC1EC0010300DFBDA3 /* Filters.swift */,
9270A4DA1EB5565400DFBDA3 /* SwitchingTableViewCell.swift */,
92108A321ED755F100675E16 /* CheckingTableViewCell.swift */,
CD466DD11DC12E1200E44DF5 /* MainTableViewController.swift */,
CD763A7D1DE253B900ADFD6B /* SRCTUtilities.swift */,
CD763A7B1DE251C400ADFD6B /* SRCTSimpleTableViewCell.swift */,
......@@ -341,6 +344,7 @@
buildActionMask = 2147483647;
files = (
92182EC41E95C38400192ABA /* LocationDetailViewController.swift in Sources */,
92108A331ED755F100675E16 /* CheckingTableViewCell.swift in Sources */,
92182EC01E95BD2C00192ABA /* LocationsListViewController.swift in Sources */,
CD763A7A1DE24EF100ADFD6B /* examplejson.swift in Sources */,
CD466DD21DC12E1200E44DF5 /* MainTableViewController.swift in Sources */,
......
......@@ -116,15 +116,15 @@
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="checkmark" indentationWidth="10" reuseIdentifier="Checkbox Filter" textLabel="rYu-5q-2u8" style="IBUITableViewCellStyleDefault" id="x5H-BH-cVX">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Checkbox Filter" textLabel="rYu-5q-2u8" style="IBUITableViewCellStyleDefault" id="x5H-BH-cVX" customClass="CheckingTableViewCell" customModule="WhatsOpen" customModuleProvider="target">
<rect key="frame" x="0.0" y="100" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="x5H-BH-cVX" id="xf1-yc-ynP">
<rect key="frame" x="0.0" y="0.0" width="336" height="43.5"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="rYu-5q-2u8">
<rect key="frame" x="15" y="0.0" width="321" height="43.5"/>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Sort By x" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="rYu-5q-2u8">
<rect key="frame" x="15" y="0.0" width="345" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
......@@ -132,6 +132,7 @@
</label>
</subviews>
</tableViewCellContentView>
<color key="tintColor" red="0.0" green="0.40000000000000002" blue="0.20000000000000001" alpha="1" colorSpace="calibratedRGB"/>
</tableViewCell>
</prototypes>
<connections>
......
//
// CheckingTableViewCell.swift
// WhatsOpen
//
// Created by Zach Knox on 5/25/17.
// Copyright © 2017 SRCT. All rights reserved.
//
import UIKit
class CheckingTableViewCell: UITableViewCell {
var onlyOne: OnlyOneChecked!
var cellIndex: Int!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
if(selected) {
onlyOne.setCheckToCellWithID(cellIndex)
super.setSelected(false, animated: animated)
}
// Configure the view for the selected state
}
}
class OnlyOneChecked {
var view: FiltersTableViewController
var cellChecked: Int //if -1, no cell is checked.
init(tableView: FiltersTableViewController, tableCellChecked: Int) {
self.view = tableView
self.cellChecked = tableCellChecked
}
func setCheckToCellWithID(_ id: Int) {
for cell in view.sortOptions {
if(id == cell.cellIndex) {
cell.accessoryType = UITableViewCellAccessoryType.checkmark
}
else {
cell.accessoryType = UITableViewCellAccessoryType.none
}
}
//also do something here to update the filters object in view
}
}
......@@ -16,10 +16,16 @@ class FiltersTableViewController: UITableViewController {
var filters: Filters!
var showOpen, showClosed: SwitchingTableViewCell!
var sortOptions: [CheckingTableViewCell] = []
var onlyOne: OnlyOneChecked!
override func viewWillAppear(_ animated: Bool) {
onlyOne = OnlyOneChecked(tableView: self, tableCellChecked: -1)
}
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
......@@ -42,35 +48,49 @@ class FiltersTableViewController: UITableViewController {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 2
if(section == 0) {
return 2
}
else if(section == 1) {
return 4
}
else {
return 0
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell
switch indexPath.section {
case 0:
let cell: SwitchingTableViewCell
switch indexPath.row {
case 0:
cell = tableView.dequeueReusableCell(withIdentifier: "Switching", for: indexPath)
cell = tableView.dequeueReusableCell(withIdentifier: "Switching", for: indexPath) as! SwitchingTableViewCell
cell.textLabel!.text = "Show Open Locations"
self.showOpen = cell
case 1:
cell = tableView.dequeueReusableCell(withIdentifier: "Switching", for: indexPath)
cell = tableView.dequeueReusableCell(withIdentifier: "Switching", for: indexPath) as! SwitchingTableViewCell
cell.textLabel!.text = "Show Closed Locations"
self.showClosed = cell
default:
cell = UITableViewCell() //this is bad don't let this happen
cell = UITableViewCell() as! SwitchingTableViewCell //this is bad don't let this happen
}
case 1:
cell = tableView.dequeueReusableCell(withIdentifier: "Checkbox Filter", for: indexPath)
let cell: CheckingTableViewCell
cell = tableView.dequeueReusableCell(withIdentifier: "Checkbox Filter", for: indexPath) as! CheckingTableViewCell
cell.onlyOne = self.onlyOne
cell.cellIndex = indexPath.row
sortOptions.append(cell)
return cell
default:
cell = UITableViewCell() //this is bad don't let this happen
let cell = UITableViewCell() //this is bad don't let this happen
return cell
}
return UITableViewCell() //shouldn't come to this
// Configure the cell...
return cell
}
/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
......@@ -113,6 +133,10 @@ class FiltersTableViewController: UITableViewController {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
//Using this code means there won't be live updates, but that only matters on the iPad with a popover
filters.showOpen = showOpen.switchControl.isOn
filters.showClosed = showClosed.switchControl.isOn
if(segue.identifier == "toFilters") {
let destination = segue.destination as! LocationsListViewController
destination.filters = self.filters
......
......@@ -182,8 +182,9 @@ class LocationsListViewController: UIViewController, UICollectionViewDelegate, U
}
else if(segue.identifier == "toFilters") {
let destination = segue.destination as! FiltersTableViewController
destination.filters = self.filters
let destination = segue.destination as! UINavigationController
let filterView = destination.topViewController as! FiltersTableViewController
filterView.filters = self.filters
}
// Pass the selected object to the new view controller.
......
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