【发布时间】:2015-07-08 21:15:15
【问题描述】:
我有一个UITableViewCell 子类,我在其中连接了来自自定义原型单元的UISwitch。 (数据是从前一个 ViewController 在 Table View 中传递的)
当我更改视图控制器时,UISwitch 的状态会变回默认值
在浏览应用程序时,我需要一些方法来记住开关的状态。
我已经搜索了一些其他主题,但似乎没有什么适合我的情况。
代码如下:
import UIKit
class TableViewCell: UITableViewCell {
@IBOutlet weak var myStaticSwitch: UISwitch!
@IBOutlet weak var cellLabel: UILabel!
@IBAction func mySwitch(sender: UISwitch) {
if myStaticSwitch.on {
self.cellLabel.text = "on"
//Do other things
}
else {
self.cellLabel.text = "off"
//Do other things
}
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
【问题讨论】:
标签: uitableview swift uinavigationcontroller uiswitch