I am wondering why this is not working please help me.
Here is my code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath
{
if (selectedIndexPath == indexPath) {
selectedIndexPath = nil;
} else {
selectedIndexPath = indexPath;
}
[self.tableView deselectRowAtIndexPath : indexPath animated : NO];
[tableView beginUpdates];
[tableView endUpdates];
}
Make sure you retain your
selectedIndexPathso it is not set tonilinadvertently.Then refer to the variable as
self.selectedIndexPathand you should be fine.But there is a second caveat.
NSIndexPathis an object, so the operator==will just compare the pointer addresses. Clearly, those will always be different because one is your variable and the other one is the method’s private variable! What you want to use is eitheror