Search code examples
objective-ciosmemory-managementxcode4

deselectRowAtIndexPath: failing in iOS5


The following works fine in iOS 4.3 but throws a EXC_BAD_ACCESS in iOS5.

if(mainTable != nil){
    [mainTable deselectRowAtIndexPath:currentIndexPath animated:YES];

mainTable is of type UITableView. It fails on the row with deselectRowAtIndexPath:. The above exception occurs when leaving the main (first) table view. The steps are: Click a row from main table view. Another table view displays. Click top left button to go back to the main table and exception occurs.

Actually, by the time

 - (void)viewDidDisappear:(BOOL)animated

is hit via breakpoint, currentIndexPath is already released in iOS5.

What can I look for here? I know iOS5 does some different things with releasing objects. Perhaps there are some additional checks I can do but I'm not sure where to start.

EDIT: It is defined as

currentCellIndex = indexPath;   

and comes from

-(void) displaySubView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath

I do have zombies enabled in the Run part of my scheme and now get the details. When I hit the above line, I see in the console:

*** -[NSIndexPath isEqual:]: message sent to deallocated instance 0x85a2010

Why does that happen in iOS5 and not in iOS 4.3? I do have a breakpoint in the dealloc on currentIndexPath and it is never hit.

I'm starting to believe this is related to ARC. I still have lots of retains/releases. I don't want to do the auto format for ARC since that is to cause more problems. I did try the flag used to disable ARC on a per file basis. That just threw a compiler error with unknown command.


Solution

  • This is not an exact answer to your question, but you might want to consider deselecting your row in viewWillAppear:

    -(void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        [mainTable deselectRowAtIndexPath:[mainTable indexPathForSelectedRow] animated:YES];
    }
    

    You need to implement this in the 'parent' view controller, where mainTable is declared.

    Regarding your actual question, can you tell us how does your @property look for currentCellIndex?