0

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** enter image description here

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.

enter image description here

Quiet Islet
  • 536
  • 1
  • 8
  • 28
  • 1
    What exactly are you trying to achieve on `didSelectRow`? Please format your question and ask specific problem. The question, in it's current state, is very broad and unlikely to receive any relevant answers – Malik Sep 11 '17 at 07:03
  • @Malik want to `push ViewController` – Quiet Islet Sep 11 '17 at 07:04

2 Answers2

2

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 
Salman Ghumsani
  • 3,647
  • 2
  • 21
  • 34
  • i am coding programmatically. next i want to push from ListTableController to DescriptionCollectionViewController. in there your code is not working. – Quiet Islet Sep 11 '17 at 07:18
  • Okay, whats error you are facing? Also, you can replace the name of view-controller. – Salman Ghumsani Sep 11 '17 at 07:21
  • after write this code `func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { let layout = UICollectionViewFlowLayout() let controller1 = DescriptionCollectionView(collectionViewLayout: layout) controller1.product_id = arrProduct[indexPath.item].id! navigationController?.pushViewController(controller1, animated: true) }` i got message `DescriptionViewController `Value of type 'DescriptionCollectionView' has no member 'product_id'` – Quiet Islet Sep 11 '17 at 07:26
  • i am working without storyboard, it is programmatically everything. – Quiet Islet Sep 11 '17 at 07:32
  • Basically, you have to set the storyboard-id in order to access the view-controller.. – Salman Ghumsani Sep 11 '17 at 07:34
  • i have three controller Everything i did programmatically, i have success to perform pushViewController from CategoryCollectionViewController to ListTableViewController. but got the problem when i went to push from ListTableViewController to DescriptionCollectionViewController. – Quiet Islet Sep 11 '17 at 08:01
  • What problem you got? – Salman Ghumsani Sep 11 '17 at 08:02
  • Brother! please come to this link to help me. I made multiple UIButton in a indexPath in a UICollectionViewCell programmatically. the UIButton does view everything except addTarget function not click..... https://stackoverflow.com/questions/46169737/swift-multiple-uibutton-in-a-indexpath-in-a-uicollectionviewcell-programmatical – Quiet Islet Sep 14 '17 at 04:04
1

You function will be something like that.

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let controller1 = NextViewControoler()
    controller1.data = dataSource["products"]["data"][indexPath.row]
    navigationController?.pushViewController(controller1, animated: true)
}

Description

  1. dataSource will be that variable who store the JSON data.

  2. dataSource["products"] will give you the key-value dictionary. dataSource["products"]["data"] will give you another key-value dictionary which contains the array of data.

  3. dataSource["products"]["data"][indexPath.row] will give you the selected item dictionary.

Please note that you might need to do some casting to get your required data.

Usman Javed
  • 2,437
  • 1
  • 17
  • 26
  • after write this code `func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let layout = UICollectionViewFlowLayout() let controller1 = DescriptionCollectionView(collectionViewLayout: layout) controller1.data = arrProduct["products"]["data"][indexPath.row] navigationController?.pushViewController(controller1, animated: true) }` `Value of type 'DescriptionCollectionView' has no member 'data'` – Quiet Islet Sep 11 '17 at 07:40
  • What value you want to pass to DescriptionCollectionView? – Usman Javed Sep 11 '17 at 07:46
  • It says that you have not declared any variable names data. – Usman Javed Sep 11 '17 at 07:47
  • please verify what value will return this arrProduct["products"]["data"][indexPath.row] statement. – Usman Javed Sep 11 '17 at 07:47
  • do you have chat own chat room – Quiet Islet Sep 11 '17 at 07:55
  • i have three controller Everything i did programmatically, i have success to perform pushViewController from CategoryCollectionViewController to ListTableViewController. but got the problem when i went to push from ListTableViewController to DescriptionCollectionViewController. – Quiet Islet Sep 11 '17 at 08:01
  • I didn't have a chat room but you can create and invite me in. – Usman Javed Sep 11 '17 at 09:06
  • come to my chat room https://chat.stackoverflow.com/rooms/154116/azmal-tech – Quiet Islet Sep 11 '17 at 09:11
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/154118/discussion-between-azmal-tech-and-usman-javed). – Quiet Islet Sep 11 '17 at 09:13
  • @AzmalTech - what the issue u faced bro – Anbu.Karthik Sep 11 '17 at 10:28
  • @Anbu.Karthik i am making mistake to write code in `didSelectRowAt indextPath` to push for collectionViewController – Quiet Islet Sep 11 '17 at 10:29
  • collectionViewController is your VC or else can you show the code related to collectionViewController – Anbu.Karthik Sep 11 '17 at 10:30
  • @Anbu.Karthik i have three controller Everything i did programmatically, i have been success to perform pushViewController from CategoryCollectionViewController to ListTableViewController. but got the problem when i went to push from ListTableViewController to DescriptionCollectionViewController. – Quiet Islet Sep 11 '17 at 10:33
  • what the problem u facing bro but got the problem when i went to push – Anbu.Karthik Sep 11 '17 at 10:33
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/154130/discussion-between-azmal-tech-and-anbu-karthik). – Quiet Islet Sep 11 '17 at 10:34
  • @UsmanJaved Brother! please come to this link to help me. https://stackoverflow.com/questions/46169737/swift-multiple-uibutton-in-a-indexpath-in-a-uicollectionviewcell-programmatical – Quiet Islet Sep 14 '17 at 04:03