斯威夫特:didSelectItemAtIndexpath函数不适用于json [英] Swift: didSelectItemAtIndexpath function not work of json
问题描述
didSelectRowAt_indexPath
函数中编写什么代码。 第一个CategoryCollectionViewController
覆盖func collectionView(_ collectionView:UICollectionView,didSelectItemAt indexPath:IndexPath){
让controller1 = ListTableView()
controller1.product_id = arrCategory [indexPath.item] .id!
navigationController?.pushViewController(controller1,animation:true)
}
* * CategoryCollectionViewController Json Web文件**
第二个ListTableViewController
重写func tableView(_ tableView:UITableView,didSelectRowAt indexPath:IndexPath){
告诉我,我必须在此处编写哪些代码来推送ViewController
}
ListTableController和DescriptionCollectionViewController的json网络文件相同
必须将 product_image
值加载到ListTableViewController的单元格中和 all_images
值必须加载到DescriptionCollectionViewContro中ller的单元格。
设置故事板ID :
重写func collectionView(_ collectionView :UICollectionView,didSelectItemAt indexPath:IndexPath){
让controller1 = self.storyboard?.instantiateViewController(withIdentifier: ListTableView)一样! ListTableView
navigationController?.pushViewController(controller1,animation:true)
}
我假设StoryBoard ID与您的控制器类名称相同,因此您可以在StoryBoard->身份检查器中设置StoryBoard ID。
注意:-替换推入另一个视图控制器时的标识符就像这样:
let controller1 = self.storyboard?.instantiateViewController (withIdentifier: DescriptionCollectionViewController)为!说明CollectionViewController
i have three Controller. in first CategoryCollectionViewController, next listTableViewController and finally has DescriptionCollectionViewController. in Controllers passed json data perfectly. but i got no idea what code i should write in didSelectRowAt_indexPath
function of ListTableViewController.
The first 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 web file**
The second ListTableViewController
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tell me please what code i have to write here for push ViewController
}
ListTableController and DescriptionCollectionViewController's json web file is same
just different is product_image
value have to load in ListTableViewController's cell and all_images
value have to load in DescriptionCollectionViewController's cell.
You have to write this code for pushing view-controller after setting the Storyboard Id:
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let controller1 = self.storyboard?.instantiateViewController(withIdentifier:"ListTableView") as! ListTableView
navigationController?.pushViewController(controller1, animated: true)
}
I am assuming that the StoryBoard Id will be same as your controller class name so you can set StoryBoard Id in StoryBoard -> identity inspector.
NOTE:- Replace the identifier in case of push another view controller Just like that:
let controller1 = self.storyboard?.instantiateViewController(withIdentifier:"DescriptionCollectionViewController") as! DescriptionCollectionViewController
这篇关于斯威夫特:didSelectItemAtIndexpath函数不适用于json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!