在现有部分创建 PushRow 并在运行时传递值

Create PushRow in existing section and pass value in runtime

如何动态创建 PushRow 并从 alamofire 函数传递值。这是我的 alamofire 函数,我想用 alamofire 响应创建 pushRow

nw.getJsonData(api: Api.assetCategory) { (response, error) in

}

func createPushRow(_ title: String, _ placeholder: String, _ options: [String]) {
    form +++ Section("Choose " + title)
        <<< PushRow<String>() { row in
            row.title = title.lowercased()
            row.selectorTitle = "Pick " + title.lowercased()
            row.options = options
    }
}

您可以像这样更改 PushRow 的选项:

(form.rowBy(tag: "<tagOfRow>") as? PushRow<String>)?.options = ["", "", ""]

或者您可以将行初始值设定项中的 optionsProvider 设置为 lazy 并在每次选择 PushRow 时获取选项。

form +++ Section("Choose " + title)
    <<< PushRow<String>() { row in
            row.optionsProvider = .lazy({ (formViewController, completion) in
                // Call Alamofire to get options
                // options = ...
                completion(options)
            })
            // .... other set up
        }