【发布时间】:2016-02-03 21:28:31
【问题描述】:
我有这个函数,它得到一个 UISwitch 与触发该函数的按钮具有相同的标记值,然后它意味着将 UISwitch 的状态更改为 true:
let tagToSwitch = self.view.viewWithTag(sender.tag) as? UISwitch
tagToSwitch?.setOn(true, animated: true)
但是这不起作用,如果我更改 tagToSwitch! 应用程序崩溃并返回错误 'fatal error: unexpectedly found nil while unwrapping an Optional value' 尽管我不确定我在哪里出错,就像我之前打印 sender.tag 值时一样这样,它会打印出正确的值。
感谢任何帮助。
【问题讨论】:
标签: xcode swift uiswitch viewwithtag