Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未调用准备函数-swift 3_Ios_Swift_Xcode_Swift3 - Fatal编程技术网

Ios 未调用准备函数-swift 3

Ios 未调用准备函数-swift 3,ios,swift,xcode,swift3,Ios,Swift,Xcode,Swift3,我有一个收藏视图。每个项目都应该将数据传递给第二个视图,在另一个世界中,我希望通过navigationController将当前视图传递给第二个视图 class GroupsViewController: UIViewController ,UICollectionViewDataSource, UICollectionViewDelegate { .... func collectionView(_ collectionView: UICollectionView, didSelectIte

我有一个收藏视图。每个项目都应该将数据传递给第二个视图,在另一个世界中,我希望通过
navigationController
将当前视图传递给第二个视图

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")
        }
    }

但在控制台日志中没有显示任何内容

未调用它,因为
pushViewController
不执行序列

您需要调用
performsgue(带有标识符:“GroupSubnetableViewController”,发送者:self)
而不是
pushViewController


当然,您还需要在故事板中设置它。

您在这里混合了两件事
perfmsegue
pushViewController
。使用
performsgue
执行序列时调用。因此,从
源VC
目标VC
创建一个序列

如果要使用
pushViewController
,只需向
ViewController
输入cast
UIViewController
即可传递数据

let vc = self.storyboard!.instantiateViewController(withIdentifier: "GroupSubOneTableViewController") as! GroupSubOneTableViewController
//pass vaue
vc.passStr = "Hello"
self.navigationController?.pushViewController(vc, animated: true)

prepare
仅在执行序列时调用