viewController.delegate不是客户ViewController类的成员

问题描述 投票:-1回答:1

很抱歉,如果这是一个非常愚蠢的问题 - 但我正在按照本教程获得模糊的背景模式

https://medium.com/@mohau/blurred-background-semi-transparent-modal-view-swift-3-xcode-tutorial-1f67566bb449

而且我已经完成了所有相同的工作,但是我在MainViewControllersModalViewControllers的代码上遇到了错误,两者都与'委托'标识符有关。

自从我上次使用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'
}

最奇怪的是,如果我从教程中下载示例,它可以正常工作。

任何帮助将不胜感激,谢谢

ios swift xcode
1个回答
3
投票

阅读本教程的其余部分。我不知道为什么作者决定这样做,但他开始使用委托,后来才介绍如何实现委托。 the tutorial的第15步解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.