ios - How do i add a Table View inside a UICollection View Cell Using Swift? -


how add table view inside uicollectionviewcell? i'm not sure start. how table view datasource , delegate out? here have tried already...

i tried google searching it, how add collection view in table view, not other way around.

 import uikit      class generalaisleviewcontroller: uiviewcontroller, uicollectionviewdatasource, uicollectionviewdelegate, uitableviewdatasource, uitableviewdelegate {          @iboutlet weak var collectionview: uicollectionview!           var tableview:uitableview = uitableview()          var collectionviewarray = ["1", "2", "3"]  var tableview1array = ["1", "2"]         var tableview2array = ["1", "2"] var tableview3array = ["1", "2"]           override func viewdidload() {             super.viewdidload()              // additional setup after loading view.               self.collectionview.delegate = self             self.collectionview.datasource = self              self.tableview.delegate = self             self.tableview.datasource = self          }          override func didreceivememorywarning() {             super.didreceivememorywarning()             // dispose of resources can recreated.         }           func collectionview(collectionview: uicollectionview, numberofitemsinsection section: int) -> int {             return collectionviewarray.count         }           func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell {              let cell:uicollectionviewcell = self.collectionview.dequeuereusablecellwithreuseidentifier("cell", forindexpath: indexpath) as! uicollectionviewcell               let datatodisplay:string = collectionviewarray[indexpath.row]              let datalabel:uilabel = cell.viewwithtag(1) as! uilabel                 datalabel.text = datatodisplay               let tableview = cell.viewwithtag(2) as! uitableview              self.tableview = tableview                 return cell         } 

adding auitableview in auicollectionview(cell) no difference vice versa.

you need clear theuitableview's delegate , datasource. code, it'sgeneralaisleviewcontroller be.

then need adduitableview cell's sub views, like:  

code:

... let tableview = cell.viewwithtag(2) as! uitableview self.tableview = tableview cell.addsubview(tableview) return cell 

then table view fetch table view cells datasource.

however, things never easier like. uitableview anduicollectionview both share reuse technique cells, every time got cell queue, reused, not created, need extremely careful handle them after got cell.

better use preparereuse clean cell's sub views before assign other properties or views cell.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -