Swift Eureka - 捕获MultivaluedSection删除操作

时间:2017-06-11 01:54:23

标签: swift eureka-forms

我正在使用带有MultivaluedSection组件的swift Eureka library。我想捕获用户删除行并更新我的应用程序状态。我看了一些例子,他们展示了如何启用删除操作,但没有一个提供捕获删除操作的能力你知道怎么做吗?

示例代码:

class MultivaluedOnlyDeleteController: FormViewController {

    @IBOutlet weak var editButton: UIBarButtonItem!

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.isEditing = false
        let nameList = ["family", "male", "female", "client"]

        let section = MultivaluedSection(multivaluedOptions: .Delete, footer: "you can swipe to delete when table.isEditing = false (Not Editing)")


        for tag in nameList {
            section <<< TextRow {
                            $0.placeholder = "Tag Name"
                            $0.value = tag
                        }
        }


        let section2 =  MultivaluedSection(multivaluedOptions: .Delete, footer: "")
        for _ in 1..<4 {
            section2 <<< PickerInlineRow<String> {
                            $0.title = "Tap to select"
                            $0.value = "client"
                            $0.options = nameList
                         }
        }

        editButton.title = tableView.isEditing ? "Done" : "Edit"
        editButton.target = self
        editButton.action = #selector(editPressed(sender:))

        form    +++

                section

                +++

                section2
    }

    func editPressed(sender: UIBarButtonItem){
        tableView.setEditing(!tableView.isEditing, animated: true)
        editButton.title = tableView.isEditing ? "Done" : "Edit"

    }
}

2 个答案:

答案 0 :(得分:2)

在Core.swift文件中,您需要更改此功能:

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)

从公共打开,然后您可以在视图控制器中使用此功能。

usage in View Controller

答案 1 :(得分:0)

刚刚提交了PR on GitHub,但在获得批准之前,请随时使用my forked repository

以下是一个小例子:

section <<< TextRow {
                  $0.placeholder = "Tag Name"
                  $0.value = tag
             }.willBeRemoved({ (textRow) in
                  // do your stuff here
            })

如果你使用 CocoaPods ,作为临时解决方案只需替换

pod 'Eureka'

pod 'Eureka', :git => 'https://github.com/AdamStreet/Eureka.git', :branch => 'multivaluedsection-delete-callback'