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 .
|
| 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];
}
|
| | 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
| | 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
| | 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
| | 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
| | Thank you.... I also had this issue on iOS7 only.... – lepert Mar 25 '14 at 4:42
|
|
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理