2016-10-01 84 views
0

我正在我的類上創建一個擴展,以符合協議'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; 

我如何去有關解決此問題?

回答

0

你的實現中有一些錯誤。

替換此

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?) 
+0

我仍然得到兩個「修復它」的錯誤,要我從NSError改回到錯誤 –

+0

@FaisalSyed只要將'didFinishWith status'改成'didFinishWithStatus status'而不將錯誤更改爲NSError, –

+0

我會盡力而爲,讓你知道 –

相關問題