customs alertView removeFromSuperview and not found 不符合预期类型'CastingPromptViewDelegate'

customs alertView removeFromSuperview and not found does not conform to expected type 'CastingPromptViewDelegate'

我的海关 alertView 在尝试编译时遇到一些问题,它会给我以下错误

Value of type 'CastingPromptViewDelegate' has no member

'removeFromSuperview' Argument type 'CastingPromptView' does not conform to expected type 'CastingPromptViewDelegate'

在我的 watchVC 上有这个

private lazy var castingPromptView: CastingPromptView = {
    let view = CastingPromptView.instanceFromNib(castDeviceName: "test", imageURLString: "https://dsfsdf.jpg")
    view.translatesAutoresizingMaskIntoConstraints = false
    view.delegate = self
    return view
}()


//cast CastingPromptView 
    class CastingPromptView: UIView{
        // MARK: - IBOutlets
        @IBOutlet weak var castTODeviceLabel: UILabel!
        @IBOutlet weak var videoImage: URLImageView?
        @IBOutlet weak var playCastingButton: UIButton!
        @IBOutlet weak var stopCastingButton: UIButton!
        @IBOutlet weak var cancelButton: UIButton!
        
        // MARK: - Properties
        public var delegate: CastingPromptViewDelegate?
        
        class func instanceFromNib(castDeviceName:String,imageURLString:String) -> CastingPromptView {
            let view = UINib(nibName: "CastingPromptView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! CastingPromptView
            view.castTODeviceLabel.text = castDeviceName
    
            view.setupView()
            return view
        }
        
        override init(frame: CGRect) {
          super.init(frame: frame)
    
        }
        
        //initWithCode to init view from xib or storyboard
        required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
          setupView()
        }
        
        private func setupView() {
     
            self.backgroundColor = .white
            self.layer.borderColor = UIColor(red: 0.98, green: 0.98, blue: 0.98, alpha: 1.00).cgColor
            self.layer.borderWidth = 1
            self.layer.cornerRadius = 12
        }
        
        @IBAction func dismissView(_ sender: Any) {
            
          self.delegate?.dismissAlert(sender: self) ->> conform to expected type 'CastingPromptViewDelegate'
        }
        
        @IBAction func stopCasting(_ sender: Any) {
            
        }
        
        @IBAction func playCasting(_ sender: Any) {
    
        }
     }
    
    // MARK: - Delegate
    protocol CastingPromptViewDelegate {
        func dismissAlert(sender: CastingPromptViewDelegate)
    
    }


extension WatchVC:CastingPromptViewDelegate {
    func dismissAlert(sender: CastingPromptViewDelegate) {
        sender.removeFromSuperview() -->Value of type 'CastingPromptViewDelegate' has no member 'removeFromSuperview'
        self.backgroundView.removeFromSuperview()
        
    }

试试这个:

protocol CastingPromptViewDelegate {
    func dismissAlert(sender: CastingPromptView) // instead of CastingPromptViewDelegate
}

那么您的分机将是:

extension WatchVC:CastingPromptViewDelegate {
    func dismissAlert(sender: CastingPromptView) {
        sender.removeFromSuperview()
        self.backgroundView.removeFromSuperview()
    }
}