UITableViewCell中的iOS输入

UITableViewCell中的iOS输入

我已经按照this教程在表内构建文本字段表单的方式进行了操作,但我设法做到了,但是在教程中,他只对字段使用了一种类型。我希望某些字段具有下拉菜单,我还要添加其他字段。

我不确定执行此操作的最佳方法,我猜测字段需要排列在数组中以使其易于管理。我在想下面的代码,这些结构目前只是通用的。

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"]),
]


编辑:我的代码正在工作,但我认为它没有正确解压缩formField对象。就是说Any类型的值没有成员名,我该如何访问这些值?

    if self.formFields[indexPath.row] is TextInput {
        if let fieldValues: Any = self.formFields[indexPath.row] as? TextInput {
            if let cell = tableView.dequeueReusableCellWithIdentifier("cellTextField") as? TextInputTableViewCell {
                print(fieldValues.name)
                return cell
            }
        }
    }

最佳答案

回答“任何人都没有会员名”的问题-删除任何人并使用

if let fieldValues = formFields[indexPath.row] as? TextInput {
   print(fieldValues.name)
}

关于ios - UITableViewCell中的iOS输入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35276730/

10-13 04:00