1

我有一个名为 AppPurchaseViewController 的视图,它从 IAPManagerm 类中调用一个函数。在我的收据被验证为应用内购买后,我想使用我在 AppPurchaseViewController 类中设置的 segue id 执行 segue。当我尝试这样做时,Xcode 给了我一个错误,上面写着“AppPurchaseViewController: 0x117e70ae0>) has no segue with identifier”。我的代码如下

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

有人能指出我正确的方向来加载这个视图吗?

4

1 回答 1

2

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

var appPurchaseVC: AppPurchaseViewController!

每当您声明您的 IAPManager 时,假设它来自 AppPurchaseViewController 类,您应该设置 IAPManager 的 appPurchaseVC 值。

var iapManager = IAPManager()
iapManager.appPurchaseVC = self

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

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

这可确保您performSegue从 AppPurchaseViewController 的情节提要实例中调用。在您当前的代码中,您正在创建 AppPurchaseViewController 的一个新实例(即,不是故事板中的那个),然后调用performSegue. 因为这个新实例不在我们的故事板中,所以它自然不能对故事板中的另一个视图控制器执行转场。

于 2019-08-03T03:02:41.110 回答