本文介绍了条带检出iOS与SWIFT 3中的情节提要集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在遵循SWIFT 3中的Stripe StandardiOS集成"示例/简单"
但是,我使用的是故事板,到目前为止,我已经集成了代码,运行良好。但我在调用此代码时在导航堆栈上实例化STPPaymentMethodsViewController时遇到问题
来自CheckoutRowView:
func didTap() {
self.onTap()
}
后跟
var onTap: () -> () = {}
到CheckoutViewController:
var paymentContext = STPPaymentContext()
let paymentRow: CheckoutRowView
viewDidLoad() {
self.paymentRow.onTap = { [weak self] _ in
self?.paymentContext.pushPaymentMethodsViewController()
}
}
每当我点击PaymentRow时,没有任何反应。它只是简单地眨眼,就像一个没有动作的按钮。将视图控制器添加到情节提要场景需要一个标识符。这就有道理了!
但是代码中没有标识符,因此添加一个在逻辑上会在运行时引发异常。不向情节提要场景添加视图控制器意味着堆栈上没有推送任何视图控制器。我错过了什么?
推荐答案
如果检查pushPaymentOptionsViewController
的代码,hostViewController
需要UINavigationController
或嵌入UINavigationController
- (void)pushPaymentOptionsViewController {
NSCAssert(self.hostViewController != nil, @"hostViewController must not be nil on STPPaymentContext when calling pushPaymentOptionsViewController on it. Next time, set the hostViewController property first!");
UINavigationController *navigationController;
if ([self.hostViewController isKindOfClass:[UINavigationController class]]) {
navigationController = (UINavigationController *)self.hostViewController;
} else {
navigationController = self.hostViewController.navigationController;
}
NSCAssert(self.hostViewController != nil, @"The payment context's hostViewController is not a navigation controller, or is not contained in one. Either make sure it is inside a navigation controller before calling pushPaymentOptionsViewController, or call presentPaymentOptionsViewController instead.");
WEAK(self);
[self.didAppearPromise voidOnSuccess:^{
STRONG(self);
if (self.state == STPPaymentContextStateNone) {
self.state = STPPaymentContextStateShowingRequestedViewController;
STPPaymentOptionsViewController *paymentOptionsViewController = [[STPPaymentOptionsViewController alloc] initWithPaymentContext:self];
self.paymentOptionsViewController = paymentOptionsViewController;
paymentOptionsViewController.prefilledInformation = self.prefilledInformation;
paymentOptionsViewController.paymentOptionsViewControllerFooterView = self.paymentOptionsViewControllerFooterView;
paymentOptionsViewController.addCardViewControllerFooterView = self.addCardViewControllerFooterView;
if (@available(iOS 11, *)) {
paymentOptionsViewController.navigationItem.largeTitleDisplayMode = self.largeTitleDisplayMode;
}
[navigationController pushViewController:paymentOptionsViewController
animated:[self transitionAnimationsEnabled]];
}
}];
}
这篇关于条带检出iOS与SWIFT 3中的情节提要集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!