如何将内容插入包含 UITextField 的自定义状态单元格?

How do you insert content to a custom status cel which contains a UITextField?

我有两个用于添加 "Routines" 的视图控制器。一个是显示所有例程的列表,一个是 edit/create 个例程。

在第一个视图控制器中,我有两种方式进入第二个控制器

  1. 通过选择一个已经创建的例程
  2. 通过按导航栏上的“+”按钮

如果按下按下选项,则应从 CoreData 实体中调用数据,并填充第二个视图控制器中的字段。

但是我得到了错误: 致命错误:在展开可选值时意外发现 nil

有人知道如何将内容插入名为 "NameCell" 且包含 UITextField 的自定义状态单元格吗?

提前致谢, 王牌

如果您在 Storyboard 的 table 视图中使用静态单元格,但想在其中一个视图中填充数据,则不实现任何 UITableViewDataSource 方法,而只是从有问题的 UILabel 创建 IBOutlet,然后您可以根据需要填充它。

class ViewController: UITableViewController {

    @IBOutlet weak var foo: UILabel!
    var bar: String!  // this is populated by `prepareForSegue` of presenting view controller

    override func viewDidLoad() {
        super.viewDidLoad()

        foo.text = bar
    }

}

正如 Table View Programming Guide for iOS 所说:

Note: If a table view in a storyboard is static, the custom subclass of UITableViewController that contains the table view should not implement the data source protocol. Instead, the table view controller should use its viewDidLoad method to populate the table view’s data. For more information, see Populating a Static Table View With Data.