表格视图中的部分名称

3

我应该如何获取文本框中的文本,并将其作为表视图中某个部分的名称?我希望在Swift和Xcode 6中完成此操作。非常感谢。


表格中的每个单元格都有UITextField吗?还是有一个self.textField设置标题? - Armin
2个回答

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

3

SWIFT 3.0

来自@Christian的答案。
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    if section == 0 {
        return ""
    } else {
        return ""
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接