ios - 如果我已经提供了 Controller ,如何提供 Adyen 结账?

标签 ios swift storyboard uikit adyen

我遇到了一个问题,我使用表格 View 作为侧边栏来显示应用程序中的某些 Controller 。当尝试预设 Adyen 结帐付款时收到错误,告诉我无法使用多重呈现,我的问题是,如何解决此问题?

我想在按下结账按钮后关闭侧边栏,或者插入侧边栏并显示其他 Controller ,但没有成功,或者我没有做对。

谢谢!

这是放置在 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
        } 
    }

这就是我在外部点击时关闭容器 View 并关闭侧边栏的方法

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)
    }
}

This is the side menu storyboard

最佳答案

恐怕这是 UIKit 的一个限制,一个 View Controller 只能呈现另一个 ViewController。

所以在我看来,你有两个选择,要么先关闭已经呈现的 SideMenuViewController,要么让 SideMenuViewController 呈现 Adyen View Controller 。

如果您使用的是 Adyen checkout SDK 3.5.0,则会向 UIViewController 的每个实例添加一个辅助属性,用于获取最上面显示的 View Controller ,请使用 MainViewController 的此属性 - 或任何其他可以呈现 adyen checkout View Controller 的 View Controller - 在其之上呈现另一个 View Controller 。

presenterViewController.adyen.topPresenter.present(secondPresentedVC, animated: true)

如果您使用的 SDK 版本中不存在此 adyen 帮助程序,则可以按如下方式实现 UIViewController 的扩展:

extension UIViewController {

    var topPresenter: UIViewController {
        var topController: UIViewController = self
        while let presenter = topController.presentedViewController {
            topController = presenter
        }
        return topController
    }

}

希望这有帮助!

关于ios - 如果我已经提供了 Controller ,如何提供 Adyen 结账?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61428335/

相关文章:

swift - CoreData - PickerView 更新 tableView

ios - 移除每个 MDCInputField 下方的标签/标签间距

ios - 如何使用 iOS5 的 viewcontroller 创建通用 View ?

objective-c - 使用另一个项目的 Storyboard

ios - 在 Swift 的 Controller 中传输值的问题

ios - 苹果游戏中心 "Delete test data"

ios - 在 IOS 上使用 Facebook 应用程序打开 Facebook 群组页面

swift - 如何在 Swift 中读取 3 个字节中的 19 位?

iphone - iOS Storyboard 连接松动?

objective-c - 从 UIAlertViewDelegate 回调返回后台线程