tableView:canEditRowAtIndexPath: crash when popping viewController

前端 未结 4 1173
暗喜
暗喜 2021-01-30 13:29

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 met

相关标签:
4条回答
  • 2021-01-30 13:50
    1. Use

      tableview.delegate = nil in dealloc()

    2. Use

      tableView=nil

    0 讨论(0)
  • 2021-01-30 13:55

    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];
    }
    
    0 讨论(0)
  • 2021-01-30 14:03

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

    0 讨论(0)
  • 2021-01-30 14:08

    I know this is an old post, but I recently had this problem, and thought others might benefit from what I found: I am using Xcode 9 and iOS 11, and I am employing the new method of using a SearchController. If I clicked the system back button while I was searching, I got the fatal on tableView(_: canEditRowAt indexPath:). Changing setEditing to false did not solve my issue. The problem was that I returned true/false in my canEditRowAt override depending upon if my data source had records, but when I was searching, I had a different data source (a filtering array). Once I checked against the right data source, the back button worked.

    0 讨论(0)
提交回复
热议问题