I have set up a tableview with a prototype cell in storyboard. Now I want to edit the cell's subview if it is swiped, so I implemented the delegate method tableView:willBeginEditingRowAtIndexPath:. How do I get the current cell being edited from inside this method? If I use tableView:cellForRowAtIndexPath: I get a new cell, not the one I need, because subsequent calls to dequeueReusableCellWithIdentifier:forIndexPath: seem to return different objects for the same identifier and indexPath.
I can reproduce this behaviour easily with the following code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NSLog(@"cell = %@", cell);
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NSLog(@"different cell = %@", cell);
}
So when I can't use this method, how do I get the current cell that is placed at a specific indexPath? I'm using iOS 6.
dequeueReusableCellWithIdentifier
will return different cells because that's what this method does: It's basically 'create a new cell for me, or give me a old one if it's no longer in use'.cellForRowAtIndexPath
will always return the same cell as long as the cell is visilbe. If you scroll away and back again, the cell previously used may have been reused for another row. – Vegar May 29 '13 at 10:51