All Solutions


#1

Bronze:

Assuming you have got everything working prior to doing the challenge:

In BNRItemsViewController.m:

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @“Remove”;
}

That’s it.

Silver:
In BNRItemsViewController.m

This is to add the No more items! to the last row:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@“tableView cellForRowAtIndexPath with section: %ld row : %ld”,indexPath.section, indexPath.row) ;
// Get a new or recycled cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@“UITableViewCell” forIndexPath:indexPath];
if (indexPath.row == [[[BNRItemStore sharedStore]allItems]count]) {
NSLog(@“The no more item cell”);
cell.textLabel.text = @“No more items!”;

    return cell;
}
// Set the text on the cell with the description of the item
// that is at the nth index of items, where n = row this cell
// will appear in on the tableview
NSArray *items = [[BNRItemStore sharedStore]allItems];
BNRItem *item = items[indexPath.row];

cell.textLabel.text = [item description];
return cell;

}

This method prevent the row from being moved:

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == [[[BNRItemStore sharedStore]allItems]count]) {
return NO;
}
return YES;
}

And that’s it.

Gold:

This method prevents the last row from being replaced.

In BNRItemsViewController.m:

  • (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
    {
    if (proposedDestinationIndexPath.row == [[[BNRItemStore sharedStore]allItems]count]) {
    return sourceIndexPath;
    }
    else {
    return proposedDestinationIndexPath;
    }
    }

^This method basically does the following: when the user hover the selected row over the last row the selected row will just return to its original row (you should look up apple documentation for more info).

That’s it!