Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tableView:canEditRowAtIndexPath: crash when popping viewController

I have a viewController with a UITableView, the rows of which I allow to edit (delete) with a swipe - much like in the Mail app. I do it with, among other, this method:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

    return YES;
}

However, if I have a delete button revealed, and at the same time I use back navigation of my UINavigationController, i.e. when I popViewControllerAnimated:, the app crashes with the following message:

[ViewController tableView:canEditRowAtIndexPath:]: message sent to deallocated instance 0xaae64d0

How can I resolve this problem?

like image 996
artooras Avatar asked Oct 07 '13 16:10

artooras


2 Answers

In your view controller's dealloc method, set the table view's editing property to NO.

like image 121
Guy Kogus Avatar answered Oct 18 '22 14:10

Guy Kogus


I had the same problem, but I was using ARC and I didn't want to be mucking about in the dealloc method. Doing it in viewWillDisappear was sufficient to stop the crash.

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [table setEditing:NO];
}
like image 31
Nathan Rabe Avatar answered Oct 18 '22 13:10

Nathan Rabe