I understand the reason why message sent to deallocated instance 0xebba1b0 is called, it is because I am sending a message to an object which is no longer in memory.
So here’s my scenario. I have a ZoomedViewController which has a UITableView in it. The UITableView has a custom UITableViewCell, which has an attributed label as a subview. When a link is pressed on the attributed label (which in turns triggers didSelectRowAtIndexPath) it delegates to my MainViewController and calls the method closeZoomedImageVC in MainViewController:
-(void) closeZoomedImageVC
{
[self.zoomedImageContainer_ removeFromParentViewController];
[self.zoomedImageContainer_.view removeFromSuperview];
}
the issue is that when that didSelectRowAtIndexPath is triggered, then zoomedImageContainer_ is already gone. How do I solve this then?
To illustrate the point better, basically when I do:
[self performSelector:@selector(closeZoomedImageVC) withObject:nil afterDelay:1.0];
this doesn’t cause the crash anymore, but this is not a solution as it is hacky. What this does is it lets didSelectRowAtIndexPath to be executed first before it is deallocated.
Store a reference to your
UITableViewinZoomedViewController:Make sure to connect the outlet in Interface Builder. Now, when your
zoomedImageContainer_.viewis removed, it won’t dealloc theUITableViewuntil you release that reference as well.You also need to store a
strongreference to yourZoomedViewControllerinMainViewController, and only set that tonilafter you have saved the selected row back inMainViewController.