Gold challenge issue


#1

First of all i want to say that i already have solved the challenge. I used the following approach:-
In ItemsViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"hello");
    NSLog(@"%@",headerView);
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    // Configure the cell...
    if (!cell) {
        cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    NSLog(@"IndexPath- %@",[tableView indexPathForCell:cell]);
    BNRItem *p;
    if ([indexPath row]< totalRows-1) {
        p= [[[BNRItemStore sharedStore] allItems] objectAtIndex:[indexPath row]];
        [[cell textLabel] setText:[p description]];
        if ([indexPath row]==totalRows-2) {//Second last row..(Last item pos)
            reboundIndexPath=indexPath;
            NSLog(@"rebound row- %d",reboundIndexPath.row);
        }
    }
    else if (indexPath.row==totalRows-1) { //last row
        [[cell textLabel] setText:@"No more Items"];
    }
    
    return cell;
}
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath{
    if (proposedDestinationIndexPath.row==totalRows-1) {
        NSLog(@"row of rebound cell- %d",reboundIndexPath.row);
        return reboundIndexPath;
    }
    return proposedDestinationIndexPath;
}

The bottom line is that any cell that tries to go underneath the No More items row ends up rebounding to the second last row (right above the No items row).

As you may notice that in -tableView:cellForRowAtIndexPath: method, inside the inner if clause if ([indexPath row]==totalRows-2) i assigned the object pointer reboundIndexPath the value that indexPath has been holding. And reused it in -tableView:targetIndexPathForMoveFromRowAtIndexPath:
as a return value. This solved the challenge.
Now here’s my problem with a couple of other things which i used to solve this challenge in an alternative way—
Changes made in the ‘if clause’ -tableView:cellForRowAtIndexPath: method

 if ([indexPath row]==totalRows-2) {//Second last row..(Last item pos)
           lastCell= [tableView cellForRowAtIndexPath:indexPath];//Getting the lastCell which obviously resides in second last row.
            NSLog(@"last indexPath-%@ %@",[tableView indexPathForCell],[tableView indexPathForCell:cell]);//Issue..This logs as (null),(null)
        }

followed by

- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath{
    if (proposedDestinationIndexPath.row==totalRows-1) {
        NSLog(@"row of last cell- %d",[tableView indexPathForCell].row);//logs as 0. Expected to be 4 since 'No More items' is at no.5
         return [tableView indexPathForCell]; //Returning the second last indexPath
    }
    return proposedDestinationIndexPath;
}

In short, this approach is not at all working. Inside of the if clause, i retrieved the object that resides in the second last row (which is the BNRItem row) and made an object pointer (lastCell) point to it. And then reused this pointer variable in-tableView:targetIndexPathForMoveFromRowAtIndexPath: by passing it as an argument to indexPathForCell:. This method is supposed to return an indexPath object. This is what is expected of the program. But it is just not working that way. I think there is a fundamental mistake that i’ve committed in here. Please help me figure it out. Thanks in advance.