gpt4 book ai didi

ios - 快速从类(class)中执行转场

转载 作者:行者123 更新时间:2023-11-29 05:33:11 25 4
gpt4 key购买 nike

我有一个名为 AppPurchaseViewController 的 View ,它调用 IAPManagerm 类中的函数。在我的收据被验证为应用内购买后,我想使用我在 AppPurchaseViewController 类中设置的 segue id 执行 segue。当我尝试这样做时,Xcode 给出一个错误,提示“AppPurchaseViewController: 0x117e70ae0>) 没有带有标识符的 segue”。我的代码如下

case .purchased:
print("Purchased")

self.validateReceipt(completion: {(success) in
if success {
SKPaymentQueue.default().finishTransaction(transaction)
}
else {

}
//here is where I want to perform the segue
AppPurchaseViewController().performSegue(withIdentifier:'open', sender:nil)
})

有人能给我指出正确的方向来加载此 View 吗?

最佳答案

在 IAPManager 类的顶部,您应该声明一个 AppPurchaseViewController 类型的实例,如下所示:

var appPurchaseVC: AppPurchaseViewController!

无论何时声明 IAPManager,假设它来自 AppPurchaseViewController 类,您都应该设置 IAPManager 的 appPurchaseVC 值。

var iapManager = IAPManager()
iapManager.appPurchaseVC = self

然后,在您的 IAPManager 中,稍后当您想要执行转场时,调用:

appPurchaseVC.performSegue(withIdentifier:'open', sender:nil)

这可确保您从 AppPurchaseViewController 的 Storyboard 实例调用 performSegue。在当前代码中,您将创建 AppPurchaseViewController 的一个新实例(即,不是 Storyboard中的实例),然后调用 performSegue。因为这个新实例不在我们的 Storyboard中,所以它自然无法执行到 Storyboard中另一个 View Controller 的segue。

关于ios - 快速从类(class)中执行转场,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57335070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com