我正在尝试重新加载表示另一个视图(BuyView)的视图(MyMatches)的UI。关闭BuyView后,我想重新加载MyMatches的所有视图。但是,当我尝试在“ 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()
块在视图控制器被关闭后运行,因此self.presentingViewController
已更改?也许。使用更安全:
else {
let mmvc = self.presentingViewController as! MyMatchesViewController
self.dismissViewControllerAnimated(true) {
mmvc.setupMatchesScrollContent()
}
}
在尾随闭包中使用
mmvc
之前在其中“捕获”的位置。