表视图中的节名称

时间:2015-01-25 18:00:30

标签: swift tableview textfield sections

如何获取文本字段的文本,并将其作为tableview中某个部分的名称?我想在Swift和Xcode 6中做到这一点。非常感谢。

2 个答案:

答案 0 :(得分:6)

您可以使用titleForHeaderInSection

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

答案 1 :(得分:2)

SWIFT 3.0 来自@Christian的答案。

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