ios - How to reload data in table view by tapping the cell of collection view in swift -


am developing app using swift in in 1 controller using both collection view , table view.collection view kept @ top of controller scrolls horizontally , contains near 10 cells , table view kept below collection view.i have passed json(api) data both collection , table view have call json data(another api) subcategory of before first json data , if tapp cell of collection view should call second api , reload table view again display second api data...how task??

func jsonparsingfromurl () {     alamofire.request(.post, "http://something.com", parameters: nil, encoding: .url, headers: nil).response { (req, res, data, error) -> void in         // print(res)         // print(data)          let datastring = nsstring(data: data!, encoding:nsutf8stringencoding)         print(datastring)         self.startparsing(data!)         self.collecstartparsing(data!)     }         } func startparsing(data :nsdata) {     let dict: nsdictionary!=(try! nsjsonserialization.jsonobjectwithdata(data, options: nsjsonreadingoptions.mutablecontainers)) as! nsdictionary     in 0  ..< (dict.valueforkey("subcategory") as! nsarray).count     {         arrdict.addobject((dict.valueforkey("subcategory") as! nsarray) .objectatindex(i))     }     secondtableview.reloaddata() }  func collecstartparsing(data :nsdata){     let dict: nsdictionary!=(try! nsjsonserialization.jsonobjectwithdata(data, options: nsjsonreadingoptions.mutablecontainers)) as! nsdictionary     in 0  ..< (dict.valueforkey("subcategory_icons") as! nsarray).count     {         collectionitems.addobject((dict.valueforkey("subcategory_icons") as! nsarray) .objectatindex(i))     }     firstcollectionview.reloaddata() }     

my datasource method of table , collection view:

func tableview cell row @ indexpath {      let cell = tableview.dequeuereusablecellwithidentifier("seguecell") as! secondtableviewcell      let strtitle:nsstring = arrdict[indexpath.row] .valueforkey("adtitle") as! nsstring      cell.titlelabel.text = strtitle string      return cell 

collection view:

func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell {      let cell = collectionview.dequeuereusablecellwithreuseidentifier("firstcollectionview", forindexpath: indexpath) as! firstcollectionviewcell       let strtitle:nsstring = collectionitems[indexpath.item] .valueforkey("subcategoryname") as! nsstring       cell.titlelabel.text = strtitle string      return cell 

it helps call first api , passing data.now having api have written different function:

func jsonparsingforicon () {     alamofire.request(.post, "http://www.mysecondapi.com", nil, encoding: .url, headers: nil).response { (req, res, data, error) -> void in         // print(res)         // print(data)          let datastring = nsstring(data: data!, encoding:nsutf8stringencoding)         print(datastring)     }  } 

both json(api) has same key value pair tapping cell of collection view should call second api function , reload table view according second api json data.

mr.bista answer should accepted....

just need remove array i.e.,myarray.removeallobjects()

basic skeleton:

func collectionview(_ collectionview: uicollectionview, diddeselectitemat indexpath: indexpath) {     let category = categoryarray[indexpath.row]     myapi(category.id) }  func myapi(categoryid:string) {    //pass categoryid parameter corresponding data.    callapi {      if success {         tablearray = data server         tableview.reloaddata()      } else {          //some error occurred      }     }  } 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -