ストーリーボードの識別子からセルをデキューしている場合、単体テストの方法で cellForRowAtIndexPath を呼び出し、セルを nil にしないようにするにはどうすればよいですか?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCustomCell];
cell.guestNameText.text = self.details.guestName;
return cell;
}
dequeReusableCell が呼び出され、セルが nil になった後、上にブレーク ポイントを配置します。
ETA: テストに合格するために更新された作業コード:
- (void)setUp {
[super setUp];
_detailVC_SUT = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]
instantiateViewControllerWithIdentifier:kDetailsVC];
_myService = [OCMockObject niceMockForClass:[MyService class]];
_detailVC_SUT.service = _myService;
}
- (void)test_queryForDetailsSucceeded_should_set_cell_text_fields {
[_detailVC_SUT view]; // <--- Need to load the view for this to work
Details *details = [DetailsBuilder buildStubDetails];
[_detailVC_SUT queryForDetailsSucceededWithDetails:details];
[self getFirstCellForGuestName];
}
- (void)getFirstCellForGuestName {
MyCustomTableViewCell *guestNameCell = (MyCustomTableViewCell*)[_detailVC_SUT tableView:_detailVC_SUT.detailsTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
expect(guestNameCell.guestNameText.text).to.equal(@"Mark");
}