I am just making a basic app that I can turn on and off switches to tell me if I have homework in a certain class throughout the day. The problem I am having is the reset button that changes all of the switches to off. How can I change a switch state in swift with a button? This is what I had so far:
//
// ViewController.swift
// HomeworkManager
//
// Created by Nate Parker on 9/2/14.
// Copyright (c) 2014 Nathan Parker. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func resetClicked(sender: AnyObject) {
}
@IBOutlet var spanish: UISwitch
@IBOutlet var algebra: UISwitch
@IBOutlet var amerCult: UISwitch
@IBOutlet var bio: UISwitch
@IBOutlet var col: UISwitch
}
It should just be a matter of using the setOn()
method of the switches:
@IBAction func resetClicked(sender: AnyObject) {
spanish.setOn(false, animated: true);
algebra.setOn(false, animated: true);
amerCult.setOn(false, animated: true);
bio.setOn(false, animated: true);
col.setOn(false, animated: true);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With