How do you load a prototype cell from a storyboard?

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.

UINib *nib = [UINib nibWithNibName:@"ABCNameOfYourNibCell" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"myCustomCell"];

Then use the cell like this in cellForRowAtIndexPath:

static NSString *CellIdentifier = @"myCustomCell";

ABCNameOfYourNibCell *cell = 
[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

For your testing purposes you should be able to go with:

ABCNameOfYourNibCell *testCell = 
[[ABCNameOfYourNibCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:nil];

If you need to test reuse-behaviour, you should set a reuseIdentifier here and call prepareForReuse on the cell.

Leave a Comment