ios - UICollectionView inside Static TableViewCell -


i've seen many tutorials online pertaining embedding uicollectionviews inside dynamic table view cells , subclassing collection view set delegate wondering if process different static table view cells.

i tried following example here couldn't quite follow through because seems overly complicated little no explanation. mind outlining basic steps need go through in order collection view work?

here's code far:

class featuredcontroller: uitableviewcontroller, uiscrollviewdelegate, uicollectionviewdatasource, uicollectionviewdelegate {  override func viewdidload() {     super.viewdidload()     popularcollectionview.datasource = self     popularcollectionview.delegate = self }  //mark: popular events collection view     @iboutlet weak var popularcollectionview: uicollectionview!      func collectionview(collectionview: uicollectionview, numberofitemsinsection section: int) -> int {         return 4     }      func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell {         let cell = popularcollectionview.dequeuereusablecellwithreuseidentifier("popular", forindexpath: indexpath) as! uicollectionviewcell          return cell     } 

many thanks!

if know how add collection view dynamic table view cell, adding static 1 far easier. don't need sub class @ (but doing nice idea). under hood, static table view nothing more normal table view having support hosting uitableviewcontroller set have layout in interface builder automatically. so, here's how it:

  1. dragging collection view object library in interface builder , place in cell want.
  2. make sure table view hosted table view controller.
  3. set constraints or layout collection view in cell.
  4. set collection view's datasource hosted table view controller.
  5. adding uicollectionviewdatasource conformance table view controller.
  6. implement uicollectionviewdatasource's methods, namely collectionview:numberofitemsinsection: , collectionview:cellforitematindexpath: in uitableviewcontroller.

if know how work uitableview or uicollectionview in general, should not hard follow.

update code looks should have worked. so, should check whether:

  1. you've set class of table view controller featuredcontroller class.
  2. you have wired collection view in interface builder popularcollectionview.
  3. you have prototype collection view cell identifier popular. although, should crash if haven't done so.
  4. in ib, have set table view static.

i have small example did here

interface builder

the orange view collection view greenish view prototype collection view cell identifier mycell.

data source

and set view controller collection view's data source. set in code did too.

then implement data source methods below.

@interface viewcontroller () <uicollectionviewdatasource>  @end  @implementation viewcontroller  - (nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section {     return 20; }  - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath {     uicollectionviewcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:@"mycell" forindexpath:indexpath];     return cell; }  @end 

and result:

result


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -