我有一个 Collection View 。每个项目都应该将数据传递给第二个 View ,在其他世界中,我想通过 navigationController
将当前 View 传递给第二个 View 。
class GroupsViewController: UIViewController ,UICollectionViewDataSource, UICollectionViewDelegate {
....
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// handle tap events
var group = self.items[indexPath.item]
var cat_title = group.cat_title
self.navigationController!.pushViewController(self.storyboard!.instantiateViewController(withIdentifier: "GroupSubOneTableViewController") as UIViewController, animated: true)
}
....
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print("ooopps")
if (segue.identifier == "GroupSubOneTableViewController") {
let navController = segue.destination as! UINavigationController
let detailController = navController.topViewController as! GroupSubOneTableViewController
//detailController.currentId = nextId!
print("selected GroupSubOneTableViewController")
}
}
但在控制台日志中没有显示任何内容!
最佳答案
你在这里混合了两个东西 perfomSegue
和 pushViewController
。 performSegue(withIdentifier:sender:)
当您使用 performSegue
执行 segue 时调用。因此,创建一个从 SourceVC
到 DestinationVC
的转场。
如果你想使用 pushViewController
然后简单地输入 cast UIViewController
到你的 ViewController
传递数据。
let vc = self.storyboard!.instantiateViewController(withIdentifier: "GroupSubOneTableViewController") as! GroupSubOneTableViewController
//pass vaue
vc.passStr = "Hello"
self.navigationController?.pushViewController(vc, animated: true)
关于ios - 未调用准备函数 - swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42812606/