Swift 将数据发送到不同故事板中的视图控制器



我正在尝试将对象发送到不同故事板中的视图控制器。

Todo所以我尝试了这个,但它总是零:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let link = list[indexPath.row].link
self.object.cat = link
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "SelectContacts")
self.present(controller, animated: true, completion: nil)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destVC = segue.destination as! SelectContactsViewController
destVC.object = object
}

你需要

let controller = self.storyboard!.instantiateViewController(withIdentifier: "SelectContacts") as! SelectContactsViewController
controller.object = link
self.present(controller, animated: true, completion: nil)

使用performSegue时会触发prepareForSegue


每个 vc 都包含引用主情节提要的情节提要属性,因此不需要

let storyboard = UIStoryboard(name: "Main", bundle: nil)

相关内容

最新更新