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


29down votefavorite

12

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

answered Oct 8 ‘13 at 8:41

Guy Kogus
3,96811023

 

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
   

add a comment


up vote35down vote

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

answered Oct 8 ‘13 at 16:14

Nathan Rabe
49026

 
    
   

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

时间: 2024-10-15 12:49:06

TableView编辑状态下跳转页面的崩溃处理的相关文章

iOS开发UI篇-tableView在编辑状态下的批量操作(多选)

先看下效果图 直接上代码 #import "MyController.h" @interface MyController () { UIButton *button; } @property(nonatomic,strong)NSMutableArray *array;//数据源 @property (nonatomic,strong)NSMutableArray *selectorPatnArray;//存放选中数据 @end @implementation MyControlle

easyui 在编辑状态下,动态修改其他列值。

1 首先是自定义了一个方法uodateColumn更新列值 2 3 /** 4 *自定义的修改列值方法 5 */ 6 $.extend($.fn.datagrid.methods, { 7 updateColumn: function(datagrid,data) { 8 datagrid.each(function(){ 9 //获取缓存中的配置数据 10 var gridObj=$.data(this,"datagrid"); 11 var opts=gridObj.options

datagrid combobox事件更新编辑状态下的datagrid行

请问如何从上图状态 点击下拉的combobox中值然后在不取消datagrid编辑状态下更新这一行另一列的数据,达到下图这样的效果: 非常感谢! 给你的combobox  绑定一个onSelect 事件, 然后   onSelect:function(){   var index =  $(this).parent("tr").index();   $("table tr:eq("+index+")").find("td:nth-chi

ListView在编辑状态下不能获取修改后的值,无法更新数据

ListView在编辑状态下不能获取修改后的值,获取到的总是以前的值解决方法:在page_load事件里写: if(!IsPostBack) { ListViewBind(); } 原因:这涉及到aspx页各事件的执行顺序,因为如果没有判断IsPostBack,每次点更新时page_load都会去执行ListViewBind(),对ListView进行重新绑定,那你再去获取ListView里的值时当然就是以前的值了,这样写后ListView没有被重新绑定,里面的数据就还是以前的,所以就可以获取到

解决:WdatePicker新增状态下只能取比当前月份大的月份,编辑状态下只能取比当前input里指定月份的月份大的值

onclick="WdatePicker({ dateFmt: 'yyyy-MM', autoPickDate: true, minDate: this.value==''?'%y-#{%M+1}':this.value })" 比如今天是七月份,那么只能取八月份及其以后的月份,其它以前的月份是点不动的: 如果我是编辑状态下input给的值是9月份,那么只能取9月分份及其以后的月份: 原文地址:https://www.cnblogs.com/firstcsharp/p/11133515

tableView编辑模式下删除多个cell

在编辑模式下,tableView有自带的删除多个cell的方法. 这种效果自定义写也可以,但是我这里用的是系统的. 先上效果图.核心代码: _tableView.allowsMultipleSelectionDuringEditing = YES; 至于全选删除和选择一部分删除就不上具体代码了. 如果想要点击cell后的颜色,代码如下: //选中cell的背景色 UIImageView *imageView = [[UIImageView alloc]init]; imageView.backg

文本框编辑状态下隐藏键盘的方式

#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //让键盘称为第一响应者(进入当前的界面,键盘就弹出来) [_textF becomeFirstResponder]; _textF.delegate = self; //第一种:通过UITextFieldDelegat

(编辑状态下)Reset及OnValidate使用

using UnityEngine; using System.Collections; public class Demo : MonoBehaviour { #if UNITY_EDITOR void Reset() { Debug.Log("把脚本添加到某个物体上就会执行,之后再按物体右上角小三角弹出对话框里的reset也会执行."); } void OnValidate() { Debug.Log("脚本被修改了之后就会执行"); } #endif }

cxgrid 非编辑状态下复制当前列的值 真折腾人

1.自带的CTRL +C 只能复制整行,不知是不是版本问题. 2.有分组这个代码就不行了 s:= G1DBView.DataController.Values[G1DBView.Controller.FocusedRowIndex ,G1DBView.Controller.FocusedColumnIndex]; 3.折腾后的方案: uses Clipbrd; procedure TForm28.Button1Click(Sender: TObject); var s:string; //.Fo