Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

editActionsForRowAtIndexPath not executing on iOS 8 with Xcode 7

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 !

like image 340
Logan Gallois Avatar asked Aug 28 '15 11:08

Logan Gallois


1 Answers

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
}
like image 77
Jerome Avatar answered Nov 15 '22 18:11

Jerome