swift - iOS Inputs in UITableViewCell -
i have followed this tutorial building text field form inside table , i've managed in tutorial uses single type fields. want fields have dropdowns , i'll add other fields.
i'm not sure of best way this, i'm guessing fields need in array make lot easier manage. thinking of code below, structs generic now.
struct dropdowninput { let name: string let placeholder: string let defaultvalue: string let values: [string] } struct textinput { let name: string let placeholder: string let defaultvalue: string } var formfields: [any] = [ textinput(name: "test1", placeholder: "some value", defaultvalue: ""), dropdowninput(name: "test2", placeholder: "some value", defaultvalue: "", values: ["test1","test2","test3"]), ] edit: code working think it's not unpacking formfield object properly. it's saying value of type has no member name, how can access values?
if self.formfields[indexpath.row] textinput { if let fieldvalues: = self.formfields[indexpath.row] as? textinput { if let cell = tableview.dequeuereusablecellwithidentifier("celltextfield") as? textinputtableviewcell { print(fieldvalues.name) return cell } } }
answering question "any has no member name" - remove , use
if let fieldvalues = formfields[indexpath.row] as? textinput { print(fieldvalues.name) }
Comments
Post a Comment