【发布时间】:2019-02-16 18:29:00
【问题描述】:
我使用故事板来构建布局。我正在尝试从secondViewController 访问firstViewController 中的func,但是当我使用以下代码访问它时,无论使用什么函数或插座,我总是会得到“线程1:致命错误:在展开可选值时意外发现nil”我试图访问我总是得到同样的错误。我错过了什么还是我做错了?
done位于secondViewController
func done(){
let vc = firstViewController()
vc.drawCircle(locationX: 0, locationY: 0)
}
drawCircle位于firstViewController
func drawCircle(locationX:CGFloat, locationY: CGFloat) {
let path = UIBezierPath(roundedRect: CGRect(x: locationX, y: locationY, width: radius, height: radius), cornerRadius: 50).cgPath
combinePath.addPath(path)
layer.path = combinePath
if thickness>0{
layer.strokeColor = UIColor(red: rColor, green: gColor, blue: bColor, alpha: 1).cgColor
layer.fillColor = UIColor.clear.cgColor
layer.lineWidth = thickness
}
imageView.layer.addSublayer(layer)
}
【问题讨论】:
-
你在使用故事板吗?
-
显示drawCircle函数的代码,同时指定你是使用storyboards,nibs,还是仅仅在代码中创建视图控制器
-
@Ray_Soham 是的,我正在使用情节提要
-
@Scriptable 我正在使用情节提要,我已经添加了 drawCircle 的代码,请看一下谢谢
-
好的,我想@mahmut 的回答会解决你的问题
标签: swift