Xcode 7& Swift - 具有TextField的静态UITableView不可编辑

时间:2015-09-13 20:29:42

标签: ios xcode swift uitableview

我正在尝试为我的应用程序创建一个简单的设置视图(在Swift中的Xcode7中编码)。因此,我创建了Table View Controller并将Table View Contents设置为Static Cells。我创建了部分和行,并将TextField放入每个单元格(没有边框)并进行配置,使其在故事板中显示如下:

enter image description here

这是我的场景细分:

enter image description here

当我在模拟器中运行应用程序时,它看起来像这样:

enter image description here

  • TextField占位符文字未显示
  • TextField不可编辑

任何想法为什么?

3 个答案:

答案 0 :(得分:0)

你有没有尝试过:

    YourTextField.userInteractionEnabled = true

并以编程方式设置占位符文本?

如果你把它放在我假设使用的单元格内:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    var cell = tableView.dequeueReusableCellWithIdentifier(indexPath.row, forIndexPath: indexPath) as! UITableViewCell

    cell.YourTextField.placeholder = "Your placeholder text"

    return cell
}

答案 1 :(得分:0)

校正:

您的约束可能会将文本视图移动到单元格的可见部分之外。

我会尝试删除你的约束并重新运行程序。

这是我的工作区运行状况良好的视图: enter image description here

这是指向github项目https://github.com/Rnorback/statictablewithfields

的链接

干杯!

答案 2 :(得分:0)

对我来说,这些单元格不可编辑,直到我覆盖了tableview提交编辑委托函数。

func tableView(
     _ tableView: UITableView,
     commit editingStyle: UITableViewCell.EditingStyle,
     forRowAt indexPath: IndexPath) {

     }

有点反常的想法,认为它什么也不会返回。

相关问题