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 vote 57down voteaccepted

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

share editflag
 
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]; }
share editflag
 

    
   
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: 572064792 | Nodejs:329118122 做人要厚道,转载请注明出处!














本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sunshine-anycall/p/4343859.html ,如需转载请自行联系原作者


相关文章
|
安全 网络协议 数据安全/隐私保护
2020苹果审核被拒绝原因汇总
2020苹果审核被拒绝原因汇总
1425 0
|
存储 缓存 API
Metal 简述 & API
Metal是苹果在2018年推出用于取代在苹果端的业务的图形编程接口,在2018年之前使用的是基于OpenGL ES 封装的GLKit,通过Metal相关API直接操作GPU,能最大限度的利用GPU能力。
679 0
Metal 简述 & API
|
存储 缓存 安全
OpenGL ES 入门:GLKit加载图片
OpenGL ES 入门:GLKit加载图片
296 0
OpenGL ES 入门:GLKit加载图片
|
开发者 iOS开发
iOS-UIPickerView 详解总结
写在文前 由于最近开发中经常碰到类似日期选择器相关业务使用场景,虽然这个系统控件相对来说非常简单,有点儿类似UITableView的感觉,初始化之后设置数据源,代理,完成相应的数据源方法就可以正常展示了,而且其数据源 代理方法相对来说也很少,肯花心思去思考 记忆,很快就能掌握这个控件。
1585 0
解决使用tableview的reloadSections刷新之后,sectionFooter有时会消失
//CATransaction解决刷新之后sectionFooter消失的问题 [CATransaction begin]; [CATransaction setCompletionBlock:^{ [self.
1553 0
|
iOS开发
iOS AFN的再次封装
<h2 style="margin:0px; padding:0px; font-family:simsun; line-height:25px; background-color:rgb(245,248,253)"> <br> </h2> <br style="font-family:simsun; font-size:14px; line-height:25px; backgrou
2496 0
iOS- 详解文本属性Attributes
<h3 style="margin:15px auto 2px; padding:0px; font-size:16px; font-family:Verdana,Arial,Helvetica,sans-serif"> <span style="margin:0px; padding:0px; line-height:1.5; background-color:rgb(204,255,
1493 0

热门文章

最新文章