3

I have designed a collection view + custom cell as part of a view controller in Interface Builder. I would like to create an instance of that custom cell programmatically, just so I can use it for measuring it's dynamic size. How do I create an instance of an object from a storyboard based on it's name or it's reuse identifier (not by dequeueing a reusable cell). It it was a different xib, it would have been easier, but since it's all part of one storyboard I'm not sure how to accomplish that. Thank you!

Yuval Tal
  • 645
  • 7
  • 12
  • use the collectionview name – Kishore Kumar Dec 19 '15 at 05:06
  • @KishoreKumar could you please elaborate thanks :) – Yuval Tal Dec 19 '15 at 15:36
  • Seems like it is not possible based on this answer: http://stackoverflow.com/questions/22257105/how-do-you-load-a-prototype-cell-from-a-storyboard – Yuval Tal Dec 21 '15 at 04:51
  • Why not dequeue a cell? Another option is to override 'sizeForItemAtIndexPath', but that's a flow layout delegate method and almost presupposes that you already know what size the cell should be. – AMayes Dec 27 '15 at 23:49
  • Because when you call dequeue, it's for a specific row/section. I wanted to keep that object for "measurement" purposes. – Yuval Tal Dec 27 '15 at 23:55
  • About a year later, I can say that probably calling dequeue was the right thing to do :-) – Yuval Tal Nov 03 '16 at 22:37

0 Answers0