0
UIView 하위 클래스에 인수를 전달하려고합니다. 이것은의 ViewController에 대한 내 코드입니다Swift 3의 UIView 하위 클래스에 인수 전달
"fatal error: unexpectedly found nil while unwrapping an Optional value"
: 선폭 (인수 중 하나) 그리기 함수를 호출 할 때 나는이 오류를했습니다 : 내 코드가 작동하지만, 초기화 모든 인수가 전무 후 보인다 :
import UIKit
class ViewController: UIViewController,UIGestureRecognizerDelegate,UIScrollViewDelegate {
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var matrixView = UIMatrixView(mat: [[Bool]](),gRows:20,gCols:20,lWidth:2)
override func viewDidLoad() {
super.viewDidLoad()
// scrollView.delegate = self
}
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return self.matrixView
}
}
그리고 이것은 UIView의 서브 클래스이다
import UIKit
class UIMatrixView: UIView {
var matrix : [[Bool]]!
var gridRows : Int!
var gridCols : Int!
var lineWidth : Int!
init(mat: [[Bool]], gRows : Int, gCols : Int, lWidth : Int){
print("here")
self.matrix=mat
self.gridRows=gRows
self.gridCols=gCols
self.lineWidth=lWidth
super.init(frame: CGRect())
print(lineWidth)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
}
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
print(lineWidth)
}
}
어느 콘센트 나, 프로그램을 통해 matrixView' '를 생성한다. 둘 다 할 수는 없습니다. – rmaddy