13

I am testing my application on 3 devices. 2 devices on iOS 9, and one device on iOS 8. On iOS 9 the function editActionsForRowAtIndexPath is working and action is show when I swipe one cell. But on iOS 8, I can't swipe cells.

Here is my code :

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    let ShareAction = UITableViewRowAction(style: .Normal, title: "Partager", handler: { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
        if AllArticle[indexPath.row].Title != nil && AllArticle[indexPath.row].Link != nil {
            var ToShare = []
            if self.search {
                ToShare = [ArticleFiltered[indexPath.row].Link!]
            } else {
                ToShare = [AllArticle[indexPath.row].Link!]
            }
            let ActivityViewController = UIActivityViewController(activityItems: ToShare as [AnyObject], applicationActivities: nil)
            self.presentViewController(ActivityViewController, animated: true, completion: {
                self.TableView.setEditing(false, animated: true)
            })
        }
    })

    let FavoriteAction = UITableViewRowAction(style: .Normal, title: "Ajouté aux favoris", handler: { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in

        if AllArticle[indexPath.row].Favoris {
            let alreadyInView = UIAlertController(title: "Favori déjà ajouté", message: "Cet article fait déjà parti de vos favoris", preferredStyle: .Alert)
            let ActionAlert = UIAlertAction(title: "Ok", style: .Default) { (action) in }
            alreadyInView.addAction(ActionAlert)
            self.presentViewController(alreadyInView, animated: true, completion: nil)
        } else {
            AllArticle[indexPath.row].Favoris = true
            let alreadyInView = UIAlertController(title: "Favori ajouté", message: "Cet article fait maintenant parti de vos favoris", preferredStyle: .Alert)
            let ActionAlert = UIAlertAction(title: "Ok", style: .Default) { (action) in }
            alreadyInView.addAction(ActionAlert)
            self.presentViewController(alreadyInView, animated: true, completion: nil)
            Favorite.append(indexPath.row)
            saveFavoris()
        }
        self.TableView.setEditing(false, animated: true)
    })

    FavoriteAction.backgroundColor = UIColor.redColor()

    return [ShareAction, FavoriteAction]
}

And of course I added in

ViewDidLoad()

if TableView != nil {
        TableView.delegate = self
        TableView.dataSource = self
        TableView.tableFooterView = UIView(frame: CGRectZero)
        TableView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "tapTableView"))
        TableView.gestureRecognizers?.last?.delegate = self
    }

May its Xcode bug ? Any ideas ?

Thanks !

Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
Logan Gallois
  • 594
  • 5
  • 27

3 Answers3

41

Under iOS 8 editActions are enabled only if commitEditingStyle call is implemented in your delegate. Add the bellow method in your tableViewController :

- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath
{
    // All tasks are handled by blocks defined in editActionsForRowAtIndexPath, however iOS8 requires this method to enable editing
}
Jerome
  • 426
  • 5
  • 3
0

If you have custom UITableViewCell, and there have a GestureRecognizer, check the delegate methods - shouldRecognizeSimultaneouslyWithGestureRecognizer:

Juri Noga
  • 4,363
  • 7
  • 38
  • 51
  • Welcome to StackOverflow. Your answer sounds somewhat unspecific, would you mind to elaborate it? Please either describe what the methods you are talking about do or show how to apply them to the OP's case. – YakovL Jul 25 '16 at 18:46
0

Add this delegate method to class.

  func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == UITableViewCellEditingStyle.Delete {
    }
}
Alvin George
  • 14,148
  • 92
  • 64