如何动态创建tableview单元格中的多个文本字段

时间:2018-04-13 10:55:55

标签: swift4

这就是我试过的......

任何人都可以帮我理解下面创建文本字段的代码吗?有关以下代码的摘要非常有用。

func numberOfSections(in tableView: UITableView) -> Int {
    return 10
}


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    if section == 0 {
          return 4
    }else if  section == 1 {
        return 3
    }else{
        return 1
    }

}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 150
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "DynamicViewController") as! DynamicTableViewCell


    for var i in (0..<indexPath.count).reversed()
    {

            var myTextField: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 340, height: 40))
            myTextField.placeholder = "Enter Email Address \(i)"
            myTextField.backgroundColor = UIColor.brown
            cell.addSubview(myTextField)

    }
    return cell
}

0 个答案:

没有答案
相关问题