Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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
Json Swift:TableViewController didSelectRowAt索引路径函数不工作_Json_Uitableview_Collectionview - Fatal编程技术网

Json Swift:TableViewController didSelectRowAt索引路径函数不工作

Json Swift:TableViewController didSelectRowAt索引路径函数不工作,json,uitableview,collectionview,Json,Uitableview,Collectionview,有三个控制器。在第一个CollectionViewController、下一个TableViewController和最后一个CollectionViewController。第一个和第二个控制器完美地传递了json。但是在tableViewControllerdid select中,控制器不工作 第一次采集ViewController override func collectionView(_ collectionView: UICollectionView, didSelectItemAt

有三个控制器。在第一个
CollectionViewController
、下一个
TableViewController
和最后一个
CollectionViewController
。第一个和第二个控制器完美地传递了json。但是在
tableViewController
did select中,控制器不工作

第一次采集ViewController

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let controller1 = ListTableView()
        controller1.product_id = arrCategory[indexPath.item].id!
        navigationController?.pushViewController(controller1, animated: true)
}
第二个tableViewController 问题可能出在这里代码

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let layout = UICollectionViewFlowLayout()
        let controller1 = DescriptionCollectionView(collectionViewLayout: layout)
        controller1.product_id = arrProduct[indexPath.item].id!
        navigationController?.pushViewController(controller1, animated: true)
}
json web代码适用于3无collectionViewController

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let controller1 = ListTableView()
        controller1.product_id = arrCategory[indexPath.item].id!
        navigationController?.pushViewController(controller1, animated: true)
}

我建议您使用
prepareForSegue
清除代码,如下示例:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if (segue.identifier == "yourSegueIdentifier") {
        let controller = (segue.destination as! UINavigationController).topViewController as! YourSecondViewController //with UINavigationController as top view

        controller.valueFromSecondController = self.valueFromThisController
    }
}
然后在
didSelect
函数中调用:

performSegue(withIdentifier: "yourSegueIdentifier", sender: row)

希望有此帮助。

segue不能以编程方式在swift中工作。我在这里以编程方式编写所有代码。您使用的是programmaticaly segue吗?swift中有segue以编程方式编写