Skip to content

Instantly share code, notes, and snippets.

@codebeaulieu
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codebeaulieu/d8ddb1ca7366281e3121 to your computer and use it in GitHub Desktop.
Save codebeaulieu/d8ddb1ca7366281e3121 to your computer and use it in GitHub Desktop.
aero controller
//
// AeroPressTableViewController.swift
// CoffeePro
//
// Created by Dan Beaulieu on 6/11/15.
// Copyright © 2015 Dan Beaulieu. All rights reserved.
//
import UIKit
class AeroPressTableViewController: UITableViewController, SwitchCellDelegate {
var aeroSettings = [Setting]()
override func viewDidLoad() {
super.viewDidLoad()
let dict = AppDelegate().aero
for (k, v) in dict {
switch "\(v.dynamicType)" {
case "__NSCFBoolean":
let switchSet = Setting(label: k, state: v as Bool)
aeroSettings.append(switchSet)
case "__NSCFNumber":
let timeSet = Setting(label: k, time: v as Int)
aeroSettings.append(timeSet)
default: break
}
}
}
func didChangeSwitchState(sender sender: SwitchCell, isOn: Bool) {
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return aeroSettings.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let sets = aeroSettings[indexPath.row]
if(sets.settingsLabel != nil) {
print("not nil")
print(sets.settingsLabel)
}
if (sets.switchState != nil) {
tableView.registerClass(SwitchCell.self, forCellReuseIdentifier: "SwitchCell2")
let cell = tableView.dequeueReusableCellWithIdentifier("SwitchCell2", forIndexPath: indexPath) as! SwitchCell
cell.switchLabel.text = sets.settingsLabel
cell.switchState.on = sets.switchState!
//cell.cellDelegate = self
cell.backgroundColor = UIColor.clearColor()
return cell
} else {
tableView.registerClass(TimingCell.self, forCellReuseIdentifier: "IntCell2")
let cell2 = tableView.dequeueReusableCellWithIdentifier("IntCell2", forIndexPath: indexPath) as! TimingCell
cell2.timingLabel.text = sets.settingsLabel
cell2.savedTimeLabel.setTitle(String(sets.timing!), forState: UIControlState.Normal)
cell2.savedTimeLabel.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Right
return cell2
}
}
/*
// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Delete the row from the data source
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return NO if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment