簡體   English   中英

迅速上課上課

[英]Performing a segue from a class in swift

我有一個名為AppPurchaseViewController的視圖,該視圖從IAPManagerm類調用一個函數。 將收據確認為應用程序內購買后,我想使用在AppPurchaseViewController類中設置的segue ID執行segue。 當我嘗試這樣做時,Xcode給我一個錯誤,提示“ AppPurchaseViewController:0x117e70ae0>)沒有標識符標識”。 我的代碼如下

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

有人可以指出正確的方向來加載此視圖嗎?

在IAPManager類的頂部,應聲明一個AppPurchaseViewController類型的實例,如下所示:

var appPurchaseVC: AppPurchaseViewController!

每當聲明IAPManager時(假定它來自AppPurchaseViewController類中),都應設置IAPManager的appPurchaseVC值。

var iapManager = IAPManager()
iapManager.appPurchaseVC = self

然后,在以后要執行segue的時候,從IAPManager中調用:

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

這樣可以確保您從AppPurchaseViewController的情節提要實例中調用performSegue 在當前代碼中,您正在創建AppPurchaseViewController的新實例(即,不是故事板上的實例),然后調用performSegue 由於此新實例不在我們的情節提要中,因此自然無法對情節提要中的另一個視圖控制器執行segue。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM