gpt4 book ai didi

ios - Swift:didSelectItemAtIndexpath 函数不适用于 json

转载 作者:行者123 更新时间:2023-11-28 10:50:53 26 4
gpt4 key购买 nike

我有三个 Controller 。在第一个 CategoryCollectionViewController 中,接下来是 listTableViewController,最后是 DescriptionCollectionViewController。在Controllers中完美的传递了json数据。但是我不知道我应该在 ListTableViewController 的 didSelectRowAt_indexPath 函数中写什么代码。

第一个CategoryCollectionViewController

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

let controller1 = ListTableView()
controller1.product_id = arrCategory[indexPath.item].id!
navigationController?.pushViewController(controller1, animated: true)
}

** CategoryCollectionViewController Json 网页文件** enter image description here

第二个ListTableViewController

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

请告诉我我必须在这里为推送 ViewController 编写什么代码

}

ListTableController和DescriptionCollectionViewController的json web文件是一样的

只是不同的是 product_image 值必须加载到 ListTableViewController 的单元格中,而 all_images 值必须加载到 DescriptionCollectionViewController 的单元格中。

enter image description here

最佳答案

在设置 Storyboard Id 后,您必须编写此代码来推送 View Controller :

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let controller1 = self.storyboard?.instantiateViewController(withIdentifier:"ListTableView") as! ListTableView
navigationController?.pushViewController(controller1, animated: true)
}

我假设 StoryBoard Id 与您的 Controller 类名相同,因此您可以在 StoryBoard -> identity inspector 中设置 StoryBoard Id。

注意:- 在推送另一个 View Controller 的情况下替换标识符就像那样:

let controller1 = self.storyboard?.instantiateViewController(withIdentifier:"DescriptionCollectionViewController") as! DescriptionCollectionViewController 

关于ios - Swift:didSelectItemAtIndexpath 函数不适用于 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46149881/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com