6

I'm trying to leverage IBDesignable features of Swift in XCode 6 to create a subclass of UITableViewCell

I see in the WWDC demo, and on the web - that you can use a framework to create a subclass of a view (UIView) which can then be used in say, a custom UITableViewCell, which is not really what I want.

Can I do the same thing with a UITableViewCell directly? If I expose a UITableViewCell in my framework, then try to use it in Interface Builder, I don't have access to my custom view components at design time.

What's worse - I can't even get my custom view to show at run time via Outlets created on the StoryBoard.

Thanks in advance for any pointers...

Daniel D
  • 3,637
  • 5
  • 36
  • 41

1 Answers1

1

My understanding is that IBDesignable is intended to be used with subclasses of UIView that are embedded inside other views in your xib. Try creating a custom UIView subclass that is inspectable/designable, and add it as the cell’s contentView’s first subview in the xib, and do all your customization from there.

Zev Eisenberg
  • 8,080
  • 5
  • 38
  • 82
  • If the Custom UIView has a UITableView/UICollectionView it's not rendering in the storyboard. Is there any workaround? – Soumen Jun 04 '18 at 08:37
  • This has worked for me in the past. Are you sure your framework is compiling successfully in Interface Builder? Are you sure your table view is wired up to its data source and delegate? Is the table view laid out correctly so that it doesn’t have a size of zero? – Zev Eisenberg Jun 05 '18 at 12:10
  • If I place a UICollectionView in an IBDesignable Custom View and connect the delegate and data source with the view and then in the storyboard, it's not able to render the view. Even I tried to add the UICollectionView in code. As the Tableview/CollectionView has dynamic cell type I think it's not possible to render the Tableview/CollectionView with the Cell. – Soumen Jun 06 '18 at 08:03
  • It could be that rendering the table view requires multiple passes of the run loop, but I still think I had this working circa iOS 8. Maybe something has changed since then? – Zev Eisenberg Jun 06 '18 at 14:41