【发布时间】:2015-01-25 18:00:30
【问题描述】:
如何获取文本字段的文本,并将其作为表格视图中的部分名称?我想在 Swift 和 Xcode 6 中执行此操作。非常感谢。
【问题讨论】:
-
表格的每个单元格中是否都有一个 UITextField?还是有一个
self.textField设置标题?
标签: swift tableview textfield sections
如何获取文本字段的文本,并将其作为表格视图中的部分名称?我想在 Swift 和 Xcode 6 中执行此操作。非常感谢。
【问题讨论】:
self.textField 设置标题?
标签: swift tableview textfield sections
您可以使用titleForHeaderInSection。
func tableView(tableView: UITableView!, titleForHeaderInSection section: Int) -> String!{
if (section == 0){
return textfield.text
}
if (section == 1){
return textfield2.text
}
}
【讨论】:
SWIFT 3.0 来自@Christian 的回答。
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 {
return ""
} else {
return ""
}
}
【讨论】: