【问题标题】:Section Names In Table Views表视图中的部分名称
【发布时间】:2015-01-25 18:00:30
【问题描述】:

如何获取文本字段的文本,并将其作为表格视图中的部分名称?我想在 Swift 和 Xcode 6 中执行此操作。非常感谢。

【问题讨论】:

  • 表格的每个单元格中是否都有一个 UITextField?还是有一个self.textField 设置标题?

标签: swift tableview textfield sections


【解决方案1】:

您可以使用titleForHeaderInSection

func tableView(tableView: UITableView!, titleForHeaderInSection section: Int) -> String!{
        if (section == 0){
            return textfield.text
        }
        if (section == 1){
            return textfield2.text
        }
    }

【讨论】:

    【解决方案2】:

    SWIFT 3.0 来自@Christian 的回答。

    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        if section == 0 {
            return ""
        } else {
            return ""
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多