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

时间:2018-10-05 06:26:31

标签: swift alamofire eureka-forms

如何动态创建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
    }
}

1 个答案:

答案 0 :(得分:2)

您可以像这样更改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
        }