类型MyViewController不符合协议'STPPaymentContextDelegate'
问题描述:
我正在我的类上创建一个扩展,以符合协议'STPPaymentContextDelegate'。出于某种原因,编译器会抱怨,即使我已经将扩展中的所有方法都正确地声明了。类型MyViewController不符合协议'STPPaymentContextDelegate'
extension PaymentPopupViewController: STPPaymentContextDelegate {
func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error) {
self.delegate?.paymentPopupViewController(controller: self, didFinishPerhapsWithError: error as NSError?)
}
func paymentContextDidChange(_ paymentContext: STPPaymentContext) {
if paymentContext.loading {
self.indicatorView.startAnimating()
} else {
self.indicatorView.stopAnimating()
if paymentContext.selectedPaymentMethod == nil {
self.presentPaymentMehtodsViewController()
}
}
self.indicatorView.isHidden = !paymentContext.loading
self.paymentMethodLabel.isHidden = paymentContext.loading
self.changePaymentMethodButton.isEnabled = !paymentContext.loading
self.payButton.isEnabled = !paymentContext.loading && paymentContext.selectedPaymentMethod != nil
self.paymentMethodLabel.text = paymentContext.selectedPaymentMethod?.label
}
func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: STPErrorBlock) {
fatalError("Method isn't implemented because our backend makes a charge, not the app.")
}
func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {
if status == .userCancellation {
return
}
self.delegate?.paymentPopupViewController(controller: self, didFinishPerhapsWithError: error as NSError?)
}
这里是委托方法,通过该协议规定:
@protocol STPPaymentContextDelegate <NSObject>
- (void)paymentContext:(STPPaymentContext *)paymentContext didFailToLoadWithError:(NSError *)error;
- (void)paymentContextDidChange:(STPPaymentContext *)paymentContext;
- (void)paymentContext:(STPPaymentContext *)paymentContext
didCreatePaymentResult:(STPPaymentResult *)paymentResult
completion:(STPErrorBlock)completion;
- (void)paymentContext:(STPPaymentContext *)paymentContext
didFinishWithStatus:(STPPaymentStatus)status
error:(nullable NSError *)error;
我如何去有关解决此问题?
答
你的实现中有一些错误。
替换此
func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error)
随着
func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: NSError)
而更换此
func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?)
随着
func paymentContext(_ paymentContext: STPPaymentContext, didFinishWithStatus status: STPPaymentStatus, error: NSError?)
我仍然得到两个“修复它”的错误,要我从NSError改回到错误 –
@FaisalSyed只要将'didFinishWith status'改成'didFinishWithStatus status'而不将错误更改为NSError, –
我会尽力而为,让你知道 –