【发布时间】:2015-04-16 02:39:22
【问题描述】:
我试图在按下按钮时从另一个类调用方法,但它不起作用并给出致命错误(在展开可选值时意外发现 nil)。我不知道我是不是做错了什么。
这是第一个类 (FirstViewController) 的代码
@IBAction func pressButton(sender: UIButton) {
SecondViewController().pressedButton()
}
这是另一个类(SecondViewController)中的代码
func pressedButton() {
self.scrollView.setContentOffset(CGPoint(x: 320, y: 0), animated: true)
}
我将上面的代码放在viewDidLoad 之后(在 SecondViewController 的类中)。
【问题讨论】:
标签: ios swift uiscrollview