假设我有一个 firstViewController 和一个 secondViewController。第一个包含一个 firstButton,第二个包含一个 secondButton。这是我想要做的:当用户单击 secondButton 时,一些 firstButton 的属性会发生变化。
不幸的是,当我在 secondViewController 中创建 firstViewController 的实例然后尝试访问 firstButton 时,出现错误:
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
Run Code Online (Sandbox Code Playgroud)
因此,从技术上讲,我正在尝试按以下方式执行此操作:
var ins = firstViewController()
@IBAction func secondButtonisPressed(){
ins.firstButton.alpha = 0
}
Run Code Online (Sandbox Code Playgroud)
实现它的正确方法是什么?
提前致谢。