ios - 如果我已经在展示控制器,如何展示 Adyen 结帐?
问题描述
我遇到了一个问题,我使用 tableview 作为侧边栏来展示应用程序中的某些控制器。当尝试为付款预设 Adyen 结帐时,出现一个错误,告诉我我不能使用多重呈现,我的问题是,我该如何解决这个问题?
我想在按下结帐按钮后关闭侧边栏或按下侧边栏并展示其他控制器,但没有成功或者我做得不对。
谢谢!
这是放在 MainViewController 中的侧边菜单按钮
public func setSideMenuButton()
{
let button = UIButton()
button.frame = CGRect(x: self.view.frame.size.width - 65, y: self.view.frame.size.height - 160, width: 50, height: 50)
button.setImage(#imageLiteral(resourceName: "side_menu_button").withRenderingMode(.alwaysOriginal), for: .normal)
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
self.view.addSubview(button)
}
@objc func buttonAction(sender: UIButton!)
{
pauseEachExistingVideoPlayer()
guard let sideMenuViewController = storyboard?.instantiateViewController(withIdentifier: "SideMenuViewController") as? SideMenuViewController else { return }
sideMenuViewController.modalPresentationStyle = .overCurrentContext
sideMenuViewController.transitioningDelegate = self
present(sideMenuViewController, animated: true)
}
显示表格中的每个索引
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
switch indexPath.row {
case 0: present( UIStoryboard(name: "Profile", bundle: nil).instantiateViewController(withIdentifier: "UserProfileVC") as UIViewController, animated: true, completion: nil)
case 1: present( UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SR_VideoLibrary") as UIViewController, animated: true, completion: nil)
case 2: present( UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SR_Livestream") as UIViewController, animated: true, completion: nil)
case 3: return
case 4: return
case 5: present( UIStoryboard(name: "VideoLibrary", bundle: nil).instantiateViewController(withIdentifier: "ProjectsListVC") as UIViewController, animated: true, completion: nil)
case 6: present( UIStoryboard(name: "Profile", bundle: nil).instantiateViewController(withIdentifier: "GetPremiumVC") as UIViewController, animated: true, completion: nil)
default:
break
}
}
这就是我在外面点击时关闭约束视图并关闭侧边栏的方式
class SideMenuViewController: UIViewController, UITableViewDelegate
{
@IBOutlet weak var modalView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
if let view = modalView
{
addTapGesture(target: view, action: #selector(dismissController))
}
}
@objc private func dismissController()
{
dismiss(animated: true, completion: nil)
}
}
extension SideMenuViewController {
func addTapGesture(target: UIView, action: Selector, numberOfTaps: Int = 1) {
let tap = UITapGestureRecognizer(target: self, action: action)
tap.numberOfTapsRequired = numberOfTaps
target.isUserInteractionEnabled = true
target.addGestureRecognizer(tap)
}
}
解决方案
恐怕这是 UIKit 的一个限制,一个 View Controller 只能呈现另一个 ViewController。
So how I see it, you have two choices, either dismiss the already presented SideMenuViewController
first, or make the SideMenuViewController
present the Adyen view controller.
If you are using Adyen checkout SDK 3.5.0, there is a helper property added to every instance of a UIViewController that gets the top most presented view controller, use this property of the MainViewController
-or any other view controller that would make sense to present the adyen checkout view controller- to present another one on top of it.
presenterViewController.adyen.topPresenter.present(secondPresentedVC, animated: true)
if you're using a version of the SDK in which this adyen
helper is not present, you can implement an extension of UIViewController as follows:
extension UIViewController {
var topPresenter: UIViewController {
var topController: UIViewController = self
while let presenter = topController.presentedViewController {
topController = presenter
}
return topController
}
}
Hope this helps!.
推荐阅读
- javascript - 如何询问两次尝试,以便显示有关失败或获胜的通知
- angular - src 属性绑定在 angular6 中不起作用
- python - 在不从“列表”派生的情况下精简 JSON 消息
- google-maps - 仅在一个帐户上无法获得 200 美元的 Google 地图信用额度
- c#-4.0 - 有没有办法用c#逐节阅读word文档
- sap-cloud-sdk - 可以在 docker 中将工件的默认存储库配置为 Nexus 吗?
- python - 将 Python 系统调用限制为 virtualenv 或目录
- android - 将“半径”添加到图像的底部
- wordpress - WordPress:如何实现分类 CTA
- assembly - nasm 程序集:在 1004 次通过后找不到所有标签的有效值