Question about Challenges


#1

Hello,

After looking at how others had done the challenges I found that there were two different ways of doing the if checks for checking for the last row. My question is why do both ways work and how do you determine which to use?

Thanks!

Below you will find an example of the two if checks.

[code]- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == [self.tableView numberOfRowsInSection:0] - 1){

     return UITableViewCellEditingStyleNone;

 } else {

     return UITableViewCellEditingStyleDelete;
 }

}[/code]

[code]- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == [[[BNRItemStore sharedStore] allItems] count]) {

    return UITableViewCellEditingStyleNone;
    
} else {
    
    return UITableViewCellEditingStyleDelete;
}

}[/code]


#2

There is in fact another way (which is the one I use)

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

I would also like to here about the best practices by you guys.