Tests for Custom Uitableviewcell, Cellforrowatindexpath Crashes with Nil Outlets

cellForRowAtIndexPath nil during unit tests

Instantiate an actual UITableViewController and this works fine.

cellForRowAtIndexPath: crashes when trying to access arrays objectAtIndex:indexPath.row

The actual error is this:

-[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x5d10c20

In other words, you tried to run objectAtIndex: on an NSString (NSCFString), which of course does not support this method.

You call objectAtIndex: three times, in these lines:

cell.titleLabel.text = [postsArrayTitle objectAtIndex:indexPath.row];
cell.dateLabel.text = [postsArrayDate objectAtIndex:indexPath.row];
cell.cellImage.image = [UIImage imageWithContentsOfFile:[postsArrayImg objectAtIndex:indexPath.row]];

So it appears that postsArrayTitle, postsArrayDate, or postsArrayImg isn't an NSArray, but an NSString.

Related Topics

Leave a reply