嘗試編譯時,我的海關 alertView 有一些問題,它會給我以下錯誤
“CastingPromptViewDelegate”型別的值沒有成員
“removeFromSuperview”引數型別“CastingPromptView”不符合預期型別“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()
}
uj5u.com熱心網友回復:
試試這個:
protocol CastingPromptViewDelegate {
func dismissAlert(sender: CastingPromptView) // instead of CastingPromptViewDelegate
}
那么您的擴展名將是:
extension WatchVC:CastingPromptViewDelegate {
func dismissAlert(sender: CastingPromptView) {
sender.removeFromSuperview()
self.backgroundView.removeFromSuperview()
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/485207.html
上一篇:在iOS15中僅使用StoreKit2時是否必須提供“恢復購買”選項?
下一篇:顫振:PlatformException(sign_in_failed,org.openid.appauth.oauth_token,invalid_audience:受眾不是有效的客戶ID。,nul
