我有一个名为ViewImages的ViewController。在故事板内部,我设置了一个从VC(黄色图标(到ViewImages的续集。我将标识符发送到显示ExtraImages并正确设置了模式
在我的代码中,我有这个:
let destinationVC = ViewImages()
destinationVC.itemId = self.currentItemsArray[indexPath.row].itemID
destinationVC.performSegue(withIdentifier: "displayExtraImages", sender: self)
最后,我收到以下错误:
2019-10-06 19:12:40.994388-0400 SoldFor[21403:762477] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<SoldFor.ViewImages: 0x7fc2fff35360>) has no segue with identifier 'displayExtraImages''
但我确实有标识符...所以我有点困惑。任何帮助都会很棒。
你有 2 个选项
第一
let destinationVC = // load the vc from storyboard
destinationVC.itemId = self.currentItemsArray[indexPath.row].itemID
self.present(destinationVC,animated:true,completion:nil)
第二
self.performSegue(withIdentifier: "displayExtraImages", sender:self.currentItemsArray[indexPath.row].itemID )
并实施
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "displayExtraImages" {
let vc = segue.destination as! ViewImages
vc.itemId = sender as! Int
}
}
关于该代码的所有内容都是错误的:
-
它不是持有 segue 的目的地。它是来源- 可能只是
self
。所以只要告诉自己执行 segue,你就会没事的。 -
在我们到达
prepare(forSegue:)
之前,不要尝试设置destinationVC.itemId
。