Подтвердить что ты не робот

EditActionsForRowAtIndexPath не выполняется на iOS 8 с Xcode 7

Я тестирую свое приложение на 3 устройствах. 2 устройства на iOS 9 и одно устройство на iOS 8. На iOS 9 работает функция editActionsForRowAtIndexPath, и действие отображается, когда я прокручиваю одну ячейку. Но на iOS 8 я не могу прокручивать ячейки.

Вот мой код:

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]
}

И, конечно же, я добавил в

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
    }

Может ли его ошибка Xcode? Любые идеи?

Спасибо!

4b9b3361

Ответ 1

В iOS 8 editActions активируются только в том случае, если в делетете делегат реализован вызов commitEditingStyle. Добавьте следующий метод в свой 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
}

Ответ 2

Если у вас есть пользовательский UITableViewCell и есть GestureRecognizer, проверьте методы делегата - shouldRecognizeSimultaneouslyWithGestureRecognizer:

Ответ 3

Добавьте этот метод делегата в класс.

  func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == UITableViewCellEditingStyle.Delete {
    }
}