0

For some strange reason, I can no longer swipe right to left to delete a row in my UITableView. It used to work, but now it doesn't. The cells don't respond at all and the Delete 'button' never appears. I have the required function (Swift 2.3):

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
        let liftEvent = liftEvents[indexPath.row]
        coreDataStack.managedObjectContext.deleteObject(liftEvent)

        coreDataStack.saveMainContext()

        reloadData()
    }
}

I've verified that canEditRowAtIndexPath is getting called, User Interactions Enable is on, and by comparing my view controller code to several prior commits over the past couple of weeks, I've verified that the only things I've changed are related to filtering the list. I've also tried resetting the Simulator.

EDIT: Here are my table view settings in IB:

enter image description here

What else should I look for to get this working again?

Jim
  • 1,260
  • 15
  • 37
  • Have you seen this post: http://stackoverflow.com/questions/3309484/uitableviewcell-show-delete-button-on-swipe – zisoft Dec 30 '16 at 20:30
  • I didn't see that one so thanks for pointing it out. But after looking at it, I don't see what's different about it (other than it's Obj-C). It looks like I'm doing the same general thing. Am I missing something obvious? – Jim Dec 30 '16 at 20:41
  • What are you returning from canEditRowAtIndexPath? – Magnas Dec 31 '16 at 05:04
  • @Magnas I was returning `true` but then realized that method isn't necessary unless only some rows can be deleted. In my case, all of them can be deleted so I removed it. It didn't make a difference either way. None of the rows respond to swiping at all. – Jim Dec 31 '16 at 07:11
  • I just created a simple tableview to test some things. It occurs to me that I need to override 'commit editingstyle' and your method seems not to do that. I'm on Swift 3 so my syntax is a little different than yours (in 2.3?). Could you have that method call incorrect so the editor doesn't pick up the absence of override? – Magnas Dec 31 '16 at 10:03
  • I wonder if that's a difference between 2.3 and 3. If I add 'override' to that function it tells me it doesn't override anything from its superclass. – Jim Dec 31 '16 at 22:27
  • Yes, that's usually a sign that the definition isn't quite right. Comment out your function and begin typing tableview again so the auto-complete can fill in the correct method for you. – Magnas Jan 01 '17 at 04:32
  • I tried that and when I type `tableView` I don't get any tableview auto-complete suggestions at all. I even deleted and reconnected the tableView `dataSource` and `delegate` referencing outlets and it didn't make a difference. It's almost like this view controller has suddenly decided it doesn't want to work anymore. – Jim Jan 01 '17 at 07:48
  • I should have mentioned that this is a `UIViewController` to which I've added a `UITableView`, then made the view controller the `datasource` and `delegate`. – Jim Jan 01 '17 at 08:03
  • As well as connecting the UITableViewDataSource and Delegate, have you included them in your class line, something like: class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { } And maybe try creating a MasterDetail project from the template and copy the commit editing method across lock stock and barrel. – Magnas Jan 01 '17 at 10:17
  • Tending to agree with you about the view controller being plain naughty. Maybe time to recreate the thing. If all else fails, etc. – Magnas Jan 01 '17 at 10:20
  • I didn't include `UITableViewDataSource` and `UITableViewDelegate` in the class definition because I learned a while ago that it's no longer required like it used to be. Apparently you get it for free, at least when you define a `UITableViewController`. But since you mentioned it I tried it and it didn't do anything. I think I'm going to have to recreate it. Thanks for the suggestions. – Jim Jan 01 '17 at 19:26

0 Answers0