Vaisakh KP
Vaisakh KP

Reputation: 497

Create PushRow in existing section and pass value in runtime

How to create PushRow dynamically and pass value from alamofire function. This is my alamofire function and i want to create pushRow with the alamofire response

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
    }
}

Upvotes: 1

Views: 111

Answers (1)

Mathias Claassen
Mathias Claassen

Reputation: 557

You can either just change the options of the PushRow like this:

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

Or you can set the optionsProvider in the row initializer to lazy and get the options each time the PushRow is selected.

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
        }

Upvotes: 2

Related Questions