-1

我在 tableview 中添加了两个动作领先的滑动动作,但只有背景显示并且标题不可见。

func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let card = savedCards[indexPath.row]

//    if !card.isDefault{
        let makeDefault = UIContextualAction(style: .normal, title: "Make as Default") { (action, sourceView, completionHandler) in
            print("index path of default: \(indexPath)")

        }

        let closeAction = UIContextualAction(style: .normal, title:  "Mark as Read", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
            print("CloseAction ...")
            success(true)
        })
        closeAction.backgroundColor = .blue

        let swipeActionConfig = UISwipeActionsConfiguration(actions: [makeDefault,closeAction])
        swipeActionConfig.performsFirstActionWithFullSwipe = true
        return swipeActionConfig
  //  }

    return nil

}

在此处输入图像描述

4

1 回答 1

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

            let makeDefault = UIContextualAction(style: .normal, title: "Make as Default") { (action, sourceView, completionHandler) in
                print("index path of default: \(indexPath)")

            }

            let closeAction = UIContextualAction(style: .normal, title:  "Mark as Read", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
                print("CloseAction ...")
                success(true)
            })
            closeAction.backgroundColor = .blue

            let swipeActionConfig = UISwipeActionsConfiguration(actions: [makeDefault,closeAction])
            swipeActionConfig.performsFirstActionWithFullSwipe = true
            return swipeActionConfig

}

在此处输入图像描述

于 2020-05-12T12:38:12.310 回答