TableView编辑状态下跳转页面的崩溃处理


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?

 

up vote57down voteaccepted

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

shareeditflag
 
6  
   
This works but it only started happening in iOS7. Any idea why? –  Imran Oct 26 '13 at 10:49
15  
   
Because Apple's written some buggy code. –  Guy Kogus Oct 27 '13 at 22:50
    
   
Hope we are all submitted Bug Reports :) –  burrows111 Jan 20 '14 at 13:54
    
   
At first, I thought this is a random crash because of system bugs because crashlytics tells me only few people(out of thousands) having this issue. Now I know why and get my app fixed! –  benck Feb 16 '14 at 9:17
1  
   
Nice find. I see Apple still hasn't fixed this. –  Tander Mar 10 at 9:32
   

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];
}
shareeditflag
 

    
   
Is it wrong to have a dealloc method under ARC as long as you don't call [super dealloc]? –  artooras Oct 9 '13 at 9:27
   upvote
  flag
It's not wrong. The accepted answer won't break anything and will compile normally. You literally won't be allowed to call [super dealloc] or release as ARC is supposed to call them for you. My suggestion was mostly to reduce confusion since I didn't want an unusual dealloc method when none of my other classes have one. It also feels weird to be setting a property on an object moments before it will likely be released. –  Nathan Rabe Oct 9 '13 at 15:39
3  
   
This method will sometimes cause weird behaviour if you present other vcs etc so I would use the dealloc method. –  Imran Oct 26 '13 at 10:51
1  
   
viewDidDisappear: also works, which I prefer in this case as the user doesn't see the tableview transitioning out of the editing state. –  Defragged Mar 6 '14 at 13:20
1  
   
Thank you.... I also had this issue on iOS7 only.... –  lepert Mar 25 '14 at 4:42
欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 330987132 | Go:217696290 | Python:336880185 | 做人要厚道,转载请注明出处!http://www.cnblogs.com/sunshine-anycall/p/4343859.html
上一篇:免费下载 | 1分钟出票5万张!阿里文娱B端技术如何炼成?


下一篇:阿里云栖开发者沙龙-Java技术专场 (最全资料下载)