ios - 如何在快速单击按钮时更改开关状态

标签 ios xcode swift switch-statement

我只是在制作一个基本的应用程序,我可以打开和关闭开关来告诉我一天中某个类(class)是否有作业。我遇到的问题是将所有开关更改为关闭的重置按钮。如何使用按钮快速更改开关状态?这是我到目前为止所拥有的:

//
//  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


}

最佳答案

这应该只是使用 setOn() 的问题开关方法:

@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);
}

关于ios - 如何在快速单击按钮时更改开关状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25635708/

相关文章:

ios - 如何等到 NSURLResponse 被处理后再循环迭代?

ios - Enterprise build 不是通过服务器安装,而是可以通过 dropbox 安装

xcode - 苹果软件版本命名约定

ios - IOS : flex direction column overlapping elements 中的 flexbox 布局

ios - 取消按钮而不是导航 Controller 中的后退按钮

ios - 更改仍可在界面构建器/ Storyboard中覆盖的默认属性的默认值

ios - 在 Objective c 中使用 Swift 类。发生未声明的标识符错误

swift - 在 CKModifyRecordsOperation 中保存 CKRecord 和 CKShare 时出错

iphone - 无法在 EKEvent 中编程开始日期

ios - 如何在 iOS 中将照片保存到 google drive 的文件夹中