Is there a way to load a prototype cell, along with any IBOutlet connections as defined within a storyboard?
Update
I want to unit test the cell (a UICollectionViewCell for that mater), hence would like to load it outside of a UIViewController context.
Effectively, in the same way that you can load a custom view from a nib, specifying its file's owner and have its IBOutlet(s) set.
Edit: As far as I know, it's not possible to use prototype UITableViewCells from a Storyboard anywhere other than the ViewController you created it in.
I haven't tried this with unit tests yet but you can easily put your custom
UITableViewCell
into a separate nib.For using it in your view controllers you need to register the cell with your tableViews.
Then use the cell like this in
cellForRowAtIndexPath:
For your testing purposes you should be able to go with:
If you need to test reuse-behaviour, you should set a reuseIdentifier here and call
prepareForReuse
on the cell.Normally you crete an
UITableViewController
or aUITableView
. Than you should also create aUITableViewCell
class. After creating theUITableViewCell
class, go to the `UIStoryboard, select the cell :Then set the
UITableViewCell
class inside theIdentity Inspector
:Now add elements to the
UITableViewCell
and connect them with your classNow add the
CellIdentifier
inside theAttributes Inspector
:No got to your
UITableViewController
or theUIViewController
where you have theUITableViewDelegate
methods and call your cell like this (don't forget to#import
theUITableViewCell
class at the top of yourViewController
: