0

i have a simple question. I have a UITableView in which you can add and delete cells. If the first tableViewCell is deleted i want something else to happen. How could i test to see if the FIRST cell has been deleted via using an if statement?

if(//how do i test?)
{
//DO SOMETHING HERE!!
}

Thanks for the help everyone!

1 Answer 1

1

I assume that you already have a reference to the UITableViewCell that you are about to delete and the UITableView that it lives in. If so, just do

NSIndexPath indexPath = [tableView indexPathForCell:deletedCell];

and look at indexPath.row to determine the row. Note that you'll have to do this prior to the cell actually being deleted/removed from the table view.

6
  • okay, if i created a UITableViewCell in my cellForRow method, could that be the reference you are talking about? And how would i put this into an if statement? Thanks a lot for the reply! :D
    – iProRage
    Jan 11, 2012 at 4:17
  • How are you deleting the cell in the first place? Presumably it has to involve a reference to the cell you are about to delete.
    – UIAdam
    Jan 11, 2012 at 5:12
  • well, i call the commitEditingStyle method and inside i have if (editingStyle == UITableViewCellEditingStyleDelete) { [[self cells] removeObjectAtIndex:[indexPath row]]; [[self imageArray]removeObjectAtIndex:[indexPath row]]; NSArray *indexPaths = [NSArray arrayWithObject:indexPath]; [[self myTableView] deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade]; }
    – iProRage
    Jan 11, 2012 at 23:20
  • i use that to delete the cell.
    – iProRage
    Jan 11, 2012 at 23:20
  • Great, so you already have the index path of the row you are deleting. Just check if indexPath.row == 0 and that will tell you if it's the first cell or not.
    – UIAdam
    Jan 12, 2012 at 1:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.