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 ,如需转载请自行联系原作者


相关文章
输入框禁用状态 可清空输入框如何实现?组件写的
输入框禁用状态 可清空输入框如何实现?组件写的
|
6月前
|
Android开发
个人热点蓝条出现和消失时,页面下压和恢复导致页面混乱及蓝条下压页面底部控件看不到的问题
个人热点蓝条出现和消失时,页面下压和恢复导致页面混乱及蓝条下压页面底部控件看不到的问题
56 0
|
6月前
|
开发者
在用户关闭页面时,提示用户有内容未保存-论onbeforeunload事件的用法
在用户关闭页面时,提示用户有内容未保存-论onbeforeunload事件的用法
97 0
element弹出框关闭并销毁:清空弹出里的数据缓存(整理)
element弹出框关闭并销毁:清空弹出里的数据缓存(整理)
element ui 上传图片之后跳转、刷新、保存,预览和删除丢失问题
这问题困惑了我好久,在官方的element ui 的组件库中,直接拿来使用的话,只有当前显示效果,一旦刷新页面或者保存之后,就会丢失,预览和删除功能。当保存后,保存到后端接口,再次查看,图片是能渲染出来,但是由于保存页面刷新,随之整个上传过程失败,而查看所拿到的图片只是一张静态图片,要想再次预览和查看,需要重新选中上传
231 0
|
Java
网页退出登录,清空session,设置登录页面的浏览器的返回按钮失效!
网页退出登录,清空session,设置登录页面的浏览器的返回按钮失效!
171 0
|
缓存 JavaScript 前端开发