iOS edit actions for row not working with CLBUITableDelegate


#1

Ever since upgrading to couchbase lite v 1.3 for ios from 1.2.1, the tableview methods related to row edit actions are not being called.

Here is how I have a view controller set up:

class MyClass: UIViewController, CBLUITableDelegate {

...
@IBOutlet weak var tableView: UITableView!
var database: CBLDatabase!;
let datasource: CBLUITableSource = CBLUITableSource();

...

override func viewDidLoad() {
    super.viewDidLoad()
    self.database = DataService.sharedInstance.getDatabase();
    self.datasource.query =     self.database.viewNamed("userNotifsView").createQuery().asLiveQuery();
    self.datasource.tableView = self.tableView;
    self.tableView.dataSource = self.datasource;
    self.tableView.delegate = self;
}

!!! CALLED !!!
func couchTableSource(source: CBLUITableSource, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell? {
    let cell = tableView.dequeueReusableCellWithIdentifier("TestCell", forIndexPath: indexPath) as! MostViewedTableViewCell;
    let row = self.datasource.rowAtIndex(UInt(indexPath.row));
    let notif = row!.value as! NSDictionary;
    cell.mLabel?.text = notif["message"] as? String;
    return cell;
}

!!! CALLED !!!
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.deselectRowAtIndexPath(indexPath, animated: true);
}

!!! NEVER CALLED !!!
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    print("#############################");
    print("edit actions for row at index path");
    print("#############################\n\n\n\n");

    let myAction = UITableViewRowAction(style: .Normal, title: ...
    ...

    myAction.backgroundColor = UIColor.orangeColor()
    return [myAction];
}

!!! NEVER CALLED !!!
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    print("#############################");
    print("can edit row at index path");
    print("#############################\n\n\n\n");
    return true
}

!!! NEVER CALLED !!!
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    print("#############################");
    print("commit editing style");
    print("#############################\n\n\n\n");
}

The cellForRowAtIndexPath on the couch table source is being called as I can customize the cells. The didSelectRowAtIndexPath is being called, which is strange because it is a tableView method. The 3 editing action related methods aren’t being called. This was working fine about a week ago. I then moved onto other things, upgraded to v1.3 for CBL iOS and came back around to this and blugh… doesn’t work. Tried downgrading back down to 1.2.1, no good. The most on point post I found about this a guy had to delete all the connections on his storyboard, which I did and rehook everything back up. I’ve created new projects… not working anywhere.

Any ideas? Maybe I’m missing something stupid? Bug in 1.3? I havent went as far yet as trying on a different computer to see if maybe it’s an XCode issue. But, that’s on my attempt list. Anybody seen this before?

Thanks in advance.


#2

There’s a new property CBLUITableSource.deletionAllowed that defaults to false. This is because a typical query isn’t editable, so the deletion indicators shouldn’t be shown for rows. If you set this to true, it should fix your problem.


#3

man, thank you sir. That fixed the issue. For what it’s worth, I’m not actually using the swipe to delete functionality, the default ios row edit action, but rather customized the edit actions, so not deleting anything, just presenting some buttons for other stuff. Either way, i beat my head on the wall for a while over this. Thanks for your help. Very much appreciated.


#4

Yeah, it’s really my fault, I should have documented that change! But that class isn’t an official part of the API, just an extra, and that property was added as a small piece of a bigger task (making the rows animate properly) so I didn’t remember it later on… Glad it’s fixed now!


#5

I believe there is a little documentation out there on it that I found… More would be great though. I think though that I’ve had tunnel vision going on for about a week and just didn’t put 2 and 2 together when I came across that documentation. Also, I love the row animation upgrade in 1.3. I’m happy you guys did that else I was going to look into rolling a way for myself. Thanks.