Is calling cellForRowAtIndexPath: ever practical?

Viewed 3370

I've seen many many developers when implementing a UITableViewDelegate and UITableViewDataSource directly call cellForRowAtIndexPath: to either:

1) Retrieve the cell to grab a model element that they stored within the cell:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MyCell *cell = (MyCell *)[tableView cellForRowAtIndexPath:indexPath];
    int secretCode = cell.secretCode;
    LaunchMissileViewController *vc = [[LaunchMissileViewController alloc] initWithSecretCode:secretCode];
    [self.navigationController pushViewController:vc];
}

2) Attempt to style the cell (this has clear problems, but seems very common):

MyCell *cell = (MyCell *)[self cellForRowAtIndexPath:indexPath];
// or [tableView cellForRowAtIndexPat:indexPath];
cell.backgroundColor = [UIColor greenColor];

Is it safe to make the blanket statement that "only the framework should ever call cellForRowAtIndexPath:"? Or is there a practical reason one might ever call it themselves?

3 Answers
Related