0

I am trying to add accessibility ID to 2 buttons(Delete, Add) which is present in table view row when swipe left. The accessibilityIdentifier is not auto populating for deleteAction when I try to add it. Can somebody take a look.Thank you in advance

 func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

var contextualAction: [UIContextualAction] = []

// 1st button
    let deleteAction = UIContextualAction(style: .normal , title: "DELETE") { 
(action, view, handler) in
// code to remove item
    }
contextualAction.append(deleteAction)

// 2nd button
    let addAction = UIContextualAction(style: .normal , title: "Add") { (action, 
view, handler) in
// code to add item    
}
    contextualAction.append(addAction)
    let swipeAction = UISwipeActionsConfiguration(actions: contextualAction)
    swipeAction.performsFirstActionWithFullSwipe = false

    return swipeAction
}
Meri
  • 59
  • 6

1 Answers1

0

Here you are

func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
        tableView.subviews.forEach { tableSubview in
            if NSStringFromClass(type(of: tableSubview)) == "_UITableViewCellSwipeContainerView" {
                tableSubview.subviews.forEach { swipeContainerSubview in
                    if NSStringFromClass(type(of: swipeContainerSubview)) == "UISwipeActionPullView" {
                        swipeContainerSubview.subviews.enumerated().forEach { index, view in
                            // index 0 => your Delete Button
                            // index 1 => your Add Button
                            if let button = view as? UIButton {
                                button.accessibilityIdentifier = ""
                                button.titleLabel?.accessibilityIdentifier = ""
                            }
                        }
                    }
                }
            }
        }
    }
knottx_
  • 1
  • 1