您的位置:首页 > 其它

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

2015-03-17 11:01 537 查看
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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐