很抱歉,如果这是一个非常愚蠢的问题 - 但我正在按照本教程获得模糊的背景模式
而且我已经完成了所有相同的工作,但是我在MainViewControllers
和ModalViewControllers
的代码上遇到了错误,两者都与'委托'标识符有关。
自从我上次使用xcode和swift以来已经有一段时间了,所以我不知道导致错误的原因。
以下是导致错误的代码段。在MainViewController中:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let identifier = segue.identifier {
if identifier == "ShowModalView" {
if let viewController = segue.destination as? ModalViewController {
viewController.delegate = self //!! value of type 'ModalViewController' has no member 'delegate'
viewController.modalPresentationStyle = .overFullScreen
}
}
}
}
并在ModalViewController中(关闭模态视图的按钮操作)
@IBAction func cancelButtonPressed(_ sender: Any) {
dismiss(animated: true, completion: nil)
delegate?.removeBlurredBackgroundView() //use of unresolved identifier 'delegate'
}
最奇怪的是,如果我从教程中下载示例,它可以正常工作。
任何帮助将不胜感激,谢谢
阅读本教程的其余部分。我不知道为什么作者决定这样做,但他开始使用委托,后来才介绍如何实现委托。 the tutorial的第15步解决了这个问题。