Protecting "No More Items" from Detailed View


#1

With the new DetailView used in this section I noticed that we are not protecting the possible selection of “No More Items!” from being selected and thus causing an error. We do protect against editing/moving but if you select this last row the detail view will throw an error. I suppose this may depend on how you dealt with the last row but in my case I created it outside the items array so if one selected it and went to the detail view, it would attempt to access a row of the array that did not exist. In order to protect against this possibility I added a method to BNRItemsViewController that prevents this row from being selected.

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1)
    {
        return nil;
    }
    else return indexPath;
}