Open UITableView edit action buttons programmatically

前端 未结 5 2018
忘掉有多难
忘掉有多难 2020-11-29 03:54

I have a UIPageViewController that have UITableViewControllers inside it, and the swipe left gestures are conflicted between the UIPageViewCo

5条回答
  •  忘掉有多难
    2020-11-29 04:42

    In my case (swift 3, iOS11) MGSwipeTableCell works perfect. You can configure call's buttons in

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: prettyIdentifier, for: indexPath)
    
        cell.allowsButtonsWithDifferentWidth = true
        cell.rightButtons = [MGSwipeButton(title: "Delete\npermanently", backgroundColor: #colorLiteral(red: 0.9745360017, green: 0.7205639482, blue: 0.3932176828, alpha: 1)), MGSwipeButton(title: "Undo",backgroundColor: .black)]
        cell.rightSwipeSettings.transition = .rotate3D
        cell.delegate = self
    
        return cell
    }
    

    instead of

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {...}
    

    and catch touches in

    extension RecordingViewController: MGSwipeTableCellDelegate {
        func swipeTableCell(_ cell: MGSwipeTableCell, tappedButtonAt index: Int, direction: MGSwipeDirection, fromExpansion: Bool) -> Bool {
            cell.hideSwipe(animated: true)
            // do your stuff here like
            if index == 0 {
                print("right button")
            }
    
            return true
        }
    }
    

提交回复
热议问题