我正在尝试重新加载呈现另一个 View (BuyView) 的 View (MyMatches) 的 UI。当 BuyView 被关闭时,我想重新加载 MyMatches 的所有 View 。然而,当我尝试在“dismissViewController”完成时执行此操作时,我在“let mmvc = self.presentingViewController?as!MyMatchesViewController”行上遇到了“意外发现nil”错误。有谁知道为什么会发生这种情况,或者是否有更简单的方法来完成我想做的事情?下面发布的代码可在 BuyViewController 中找到:
func itemBought() {
print("Confirm tapped!")
BoughtController.globalController.sendSellerNotification(seller, match: match)
BoughtController.globalController.updateBuyer(self.item, buyer: LocalUser.user, match: self.match)
BoughtController.globalController.updateMarket(self.item, match: self.match)
BoughtController.globalController.updateSeller(self.item, seller: seller, soldPrice: self.match.matchedPrice)
self.cancel = false
if self.fromInfo == true {
self.presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
}
else {
self.dismissViewControllerAnimated(true) {
let mmvc = self.presentingViewController as! MyMatchesViewController
mmvc.setupMatchesScrollContent()
}
}
}
最佳答案
很可能,dismissViewControllerAnimated()
block 在 View Controller 被关闭后运行,因此 self.presentingViewController
发生了变化?也许。使用更安全:
else {
let mmvc = self.presentingViewController as! MyMatchesViewController
self.dismissViewControllerAnimated(true) {
mmvc.setupMatchesScrollContent()
}
}
在尾随闭包中使用 mmvc
之前“捕获”它的位置。
关于ios - 在dismissViewController回调中刷新presentingViewController的UI时意外发现nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39299657/