Reputation: 8977
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.
Upvotes: 0
Views: 746
Reputation: 8977
I found the solution to my self is to just set the allowSelection = NO in the tableView property. This will let the attributedLabel inside the UITableViewCell to have interaction but will disable didSelectRowAtIndexPath being called
Upvotes: 0
Reputation: 3491
When tapping on a cell in a table will invoke an animation to highlight selected cell, and it needs a short duration complete, so the best way is what you are doing, perform selector after a delay, I think 0.5 second is enough.
Upvotes: 0
Reputation:
Store a reference to your UITableView
in ZoomedViewController
:
@property (nonatomic, strong) IBOutlet UITableView *tableView;
Make sure to connect the outlet in Interface Builder. Now, when your zoomedImageContainer_.view
is removed, it won't dealloc the UITableView
until you release that reference as well.
You also need to store a strong
reference to your ZoomedViewController
in MainViewController
, and only set that to nil
after you have saved the selected row back in MainViewController
.
Upvotes: 2