我创建了一个自定义UIView并为其设置了协议。现在,从View Controller中,当我将委托设置为self时,我得到一个EXC_BAD_ACCESS。
--- View Controller代码------
class VerificationController: UIViewController, LoadingViewDelegate {
@IBOutlet weak var instructionView: LoadingView!
override func viewDidLoad() {
super.viewDidLoad()
instructionView.randomTextIndexes = [1]
instructionView.delegate = self
}
...
}
// "instructionView" is the UIView outlet and "LoadingView" is the class
-这是自定义的查看代码------
protocol LoadingViewDelegate {
func generated(random code:String)
}
class LoadingView: UIView {
var delegate:LoadingViewDelegate?
var randomTextIndexes:[Int] = []
}
当我尝试从视图控制器的EXC_BAD_ACCESS
方法访问委托以及randomTextIndexes
时,得到viewDidLoad()
。你能告诉我我在这里想念的吗?