card.io组件(http://components.xamarin.com/view/cardioios)有一个后备屏幕,上面有取消和完成按钮。
两者都没有做任何事情。我认为这取决于我订阅和事件,但是,没有订阅的事件。
以下是代码:
var paymentDelegate = new PaymentViewControllerDelegate();
var paymentViewController = new Card.IO.PaymentViewController(paymentDelegate);
paymentDelegate.OnScanCompleted += (viewController, cardInfo) =>
{
viewController.DismissViewController(true, null);
if (cardInfo == null)
{
}
else
{
new UIAlertView("Card Scanned!", cardInfo.CardNumber, null, "OK", null).Show();
}
};
paymentViewController.AppToken = "app-token";
// Display the card.io interface
base.PresentViewController(paymentViewController, true, () => { });
PaymentViewControllerDelegate上有一个方法,但我无法弄清楚如何处理它:
public override void UserDidCancel(PaymentViewController paymentViewController);
public override void UserDidProvideCreditCardInfo(CreditCardInfo cardInfo, PaymentViewController paymentViewController);
我想问题是组件没有公开后备视图的任何事件。
答案 0 :(得分:0)
您需要继承PaymentViewControllerDelegate
:
public class MyPaymentDelegate : PaymentViewControllerDelegate
{
public MyPaymentDelegate ()
{
}
public override void UserDidCancel (PaymentViewController paymentViewController)
{
// Implement on-cancel logic here...
base.UserDidCancel (paymentViewController);
}
public override void UserDidProvideCreditCardInfo (CreditCardInfo cardInfo, PaymentViewController paymentViewController)
{
// Implement logic for credit card info provided here...
base.UserDidProvideCreditCardInfo (cardInfo, paymentViewController);
}
}
然后在Card.IO.PaymentViewController
的构造函数中提供此类的实例:
var paymentDelegate = new MyPaymentDelegate();
var paymentViewController = new Card.IO.PaymentViewController(paymentDelegate);
答案 1 :(得分:0)
所以,我通过查看工作示例应用程序并将其与我所做的相比较来解决这个问题。
我所要做的就是扩大paymentDelegate和paymentViewController变量的范围。
答案 2 :(得分:0)
如果您查看示例,您实际上只需要订阅在OnScanCompleted
(其中cardInfo将为null)和UserDidCancel
两种情况下调用的UserDidProvideCreditCardInfo
事件。 (它不会为空)。
事实上,这是绑定的代码,所以你可以看到事件是作为“助手”制作的,所以你不必自己制作委托:
namespace Card.IO
{
public partial class PaymentViewControllerDelegate : BasePaymentViewControllerDelegate
{
public delegate void ScanCompleted(PaymentViewController viewController, CreditCardInfo cardInfo);
public event ScanCompleted OnScanCompleted;
public override void UserDidCancel (PaymentViewController paymentViewController)
{
var evt = OnScanCompleted;
if (evt != null)
evt(paymentViewController, null);
}
public override void UserDidProvideCreditCardInfo (CreditCardInfo cardInfo, PaymentViewController paymentViewController)
{
var evt = OnScanCompleted;
if (evt != null)
evt(paymentViewController, cardInfo);
}
}
}
如果您仍然真的想自己实现委托,请改为子类BasePaymentViewController
,但我认为您不需要自己创建自己的子类...
希望这有帮助!